P
Pike
Hi,
I need to download large CSV files into String objects for processing.
Unfortunately my download routine seems to be exceptionally slow. I
believe it's because of the following line
ret+="\n" + line;
If I download the csv files into Excel via Internet Explorer the
transfer takes a few seconds, but using the method below takes several
minutes.
Does anyone know how I can make the download method faster? I can't
find any java methods which will download the whole file in one go.
Thanks,
import java.io.*;
import java.net.*;
public class download {
public static String download(String filename) {
String ret="";
URL javacodingURL = null;
try {
javacodingURL = new URL(filename);
}catch(MalformedURLException e){
// Malformed URL
System.out.println("Error in given URL");
return ret;
}
try {
URLConnection connection = javacodingURL.openConnection();
BufferedReader br = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String line = "";
while ((line = br.readLine()) != null)
if(ret.equals("")){
ret=line;
}else{
ret+="\n" + line;
}
br.close();
}catch(UnknownHostException e){
System.out.println("Unknown Host");
return ret;
}catch(IOException e){
System.out.println("Error in opening URLConnection,
Reading or Writing");
return ret;
}
return ret;
}// end download method
}// end download class
I need to download large CSV files into String objects for processing.
Unfortunately my download routine seems to be exceptionally slow. I
believe it's because of the following line
ret+="\n" + line;
If I download the csv files into Excel via Internet Explorer the
transfer takes a few seconds, but using the method below takes several
minutes.
Does anyone know how I can make the download method faster? I can't
find any java methods which will download the whole file in one go.
Thanks,
import java.io.*;
import java.net.*;
public class download {
public static String download(String filename) {
String ret="";
URL javacodingURL = null;
try {
javacodingURL = new URL(filename);
}catch(MalformedURLException e){
// Malformed URL
System.out.println("Error in given URL");
return ret;
}
try {
URLConnection connection = javacodingURL.openConnection();
BufferedReader br = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String line = "";
while ((line = br.readLine()) != null)
if(ret.equals("")){
ret=line;
}else{
ret+="\n" + line;
}
br.close();
}catch(UnknownHostException e){
System.out.println("Unknown Host");
return ret;
}catch(IOException e){
System.out.println("Error in opening URLConnection,
Reading or Writing");
return ret;
}
return ret;
}// end download method
}// end download class