Hello All,
Can everyone help me to solve this problem ?
Im doing an assignment about downloading a file and write it to a new file.
My problem is the file that I was trying to download is very large, so everytime I compile my Download class and the main program, it taking very long time. To speed it up, I been tryin to modify this Download class so that it uses the StringBuilder class to instantiate the strContent object in the getURLRaw() function. However, It doesnt help much. It still very slow. So What did I do wrong ? Any suggestion ?
Here is my Download Class
Any help would be appreciate :)
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.net.*;
import java.io.*;
public class Download
{
public String getURLRaw(String strURL)
{
StringBuilder strContent = new StringBuilder(strURL);
String strContent="";
try
{
URL myWebAddress= new URL(strURL);
URLConnection myConn = myWebAddress.openConnection();
InputStream myStrIn = myConn.getInputStream();
BufferedReader myInputFile = new BufferedReader(new InputStreamReader(myStrIn));
strContent="";
for(String strLine = null; (strLine = myInputFile.readLine()) !=null;)
{
strContent += strLine + "\r\n";
}
}
catch (MalformedURLException errnum)
{
System.out.println("Error");
}
catch (IOException errnum)
{
System.out.println("Error");
}
return strContent;
}