Forums Register Login

copying files using fileReader, fileWriter

+Pie Number of slices to send: Send
public void copyfiles(String order_id) throws IOException {
File inputFile = new File("C:/XML/xmlfile.xml");
File outputFile = new File("C:/XML/" + order_id + ".xml");

FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);

int c;

while ((c = in.read() )!= -1)
out.write(c);
in.close();
out.close();
System.out.println("Renaming the XML FILE");
}
I am copying files using this method.
Input file is 10kb(356 lines) and output file
is 8kb(309 lines). It's not copying the files
completely. It is not copying last 50 lines.
Does anyone have any idea regarding this.
I will appreciate
+Pie Number of slices to send: Send
This topic is more appropriate for the IO and Streams forum. I will move it there for you.
+Pie Number of slices to send: Send
I don't know why that is happening but your method is awfuly inefficient. By using a Reader and Writer you are doing two character conversions and by reading a char at a time there is a lot of wasted calls to system routines.
Just get the size of the file, create a byte[] that size, use FileInputStream to fill the array in one gulp, write the array with FileOutputStream.
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 940 times.
Similar Threads
copying files using fileReader, fileWriter
copying zip files
copying files using fileReader, fileWriter
copying files using fileReader, fileWriter
trouble creating jar file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:46:39.