aspose file tools*
The moose likes Beginning Java and the fly likes trying to read from a file and write to a file..but.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trying to read from a file and write to a file..but.." Watch "trying to read from a file and write to a file..but.." New topic
Author

trying to read from a file and write to a file..but..

william smythe
Greenhorn

Joined: Jan 31, 2001
Posts: 6
I am working with this piece of code and it compiles fine but when i execute it says " exception in thread "main" Java.io.FileNotFoundException: ToBeCopied.txt (the system cannot find the file specified).....I have created a file with data called ToBeCopied.txt and an empty file called Copied.txt in the same directory as the code, what am i doing wrong???thanks againimport java.io.*;
public class Copy {
public static void main (String [] args) throws IOException {
File inputFile = new File("ToBeCopied.txt");
File outputFile = new File("Copied.txt");
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
int count = 0;
while((c=in.read())!= -1){
System.out.print(c + " ");
if (count++%10==1)
System.out.println();
out.write(c);
}
in.close();
out.close();
}
}
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
try this one.


Val SCJP <BR>going for SCJD
ryan burgdorfer
Ranch Hand

Joined: Jan 24, 2001
Posts: 219
Val,
You're missing some brackets towards the bottom...I won't say exactly where
~Ryan


<UL TYPE=SQUARE><I><LI>Ryan Burgdorfer<BR><LI>Java Acolyte</I></UL>
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
not only that i just found a problem in my code that i posted i'll correct it shortly.
william smythe
Greenhorn

Joined: Jan 31, 2001
Posts: 6
besides the brackets, what else is wrong val? thanks
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
i think that it's not copying info because streams are closed in my code. If you having troubles i will look farther and try to assist you let me know. It does create both textFiles though if they don't exist.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trying to read from a file and write to a file..but..