copying one file to another loses a few lines
Hello guys
I have this piece of code which copies a text file at a specific URL to a new file on the user's computer. The text file is very large - 6817 lines - and when it gets copied, the new file only contains 6764 lines.
Any idea where I may be going wrong?
Thanks in advance.
publicvoid copyReport()throws MalformedURLException, IOException{
privatestatic URL url;
privatestatic URLConnection urlC;
url =new URL("http://www.someurl.com/subdir1/subdir2/thereport.txt");
urlC = url.openConnection();
boolean b =new File("C:\\Copied").mkdir();
String localReportPath ="C:\\Copied\\"+getFileName(url.getFile());
File localReport =new File(localReportPath);
if (!localReport.exists()){
localReport.createNewFile();
}else{
localReport.delete();
localReport.createNewFile();
}
FileWriter fw =new FileWriter(localReport);
InputStream is = url.openStream();
InputStreamReader inR =new InputStreamReader(is);
BufferedReader buf =new BufferedReader(inR);
String line;
while ((line = buf.readLine()) !=null ){
fw.write(line+"\n");
}
is.close();
}
publicstatic String getFileName(String s){
String[] parts = s.split("/");
return parts[parts.length-1];
}

