• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this one.
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The City calls upon her steadfast protectors. Now for a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic