• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
william smythe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this one.
 
ryan burgdorfer
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Val,
You're missing some brackets towards the bottom...I won't say exactly where
~Ryan
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not only that i just found a problem in my code that i posted i'll correct it shortly.
 
william smythe
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
besides the brackets, what else is wrong val? thanks
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic