aspose file tools
The moose likes I/O and Streams and the fly likes copying files using fileReader, fileWriter Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "copying files using fileReader, fileWriter" Watch "copying files using fileReader, fileWriter" New topic
Author

copying files using fileReader, fileWriter

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
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


Bhasker Reddy
hennie louw
Ranch Hand

Joined: Jul 03, 2001
Posts: 56
Im not sure if this will work but try to use a filereader / writer wrapped around a bufferdreader / bufferdwriter
eg
public void readFiles() {
String data;
try {
BufferReader read = new BufferdReader(new FileReader(inputFile));
BufferdWriter write = new BufferdWriter(new FileWriter(outpurFile));

while ((data = read.readLine()) != null {
write.write(data);
write.newLine();
}
read.close();
write.close();
} catch (IOException e) {
}
}


Any Body can be paid to write good code, but brilliant code can only come from passion
J Ochoa
Greenhorn

Joined: Jan 24, 2002
Posts: 1
Originally posted by Bhasker Reddy:

out.close();

You might want to use the flush() method before this line.
out.flush();
out.close();
I had that issue until I used the flush() method. Writes out everything now.
-- Jayne
 
 
subject: copying files using fileReader, fileWriter
 
Threads others viewed
trouble creating jar file
copying files using fileReader, fileWriter
copying files using fileReader, fileWriter
copying files using fileReader, fileWriter
copying zip files
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture