• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IO

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
class SweetFile{
public static void main(String args[]){
try{
File inputfile=new File("light.txt");
FileInputStream fromfile=new FileInputStream(inputfile);
File outputfile=new File("dark.txt");
FileOutputStream tofile=new FileOutputStream(outputfile);
}catch(IOException e){}
try{
int i;
while((i=fromfile.read()) != -1)
tofile.write(i);
}catch(IOException e){}
System.out.println("It is done");
fromfile.close();
tofile.close();
}
}
This code doesn't compile.What could be possibly wrong with the code?Please suggest.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried to compile the code? No? I thought so. Please compile it and you'll see what doesn't work...
Compilation errors:

The "cannot resolve symbol" errors usually happen because you are trying to use a variable that is not in scope...
[ March 22, 2002: Message edited by: Valentin Crettaz ]
 
Tanuja Vaid
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Val,
I compiled the code lot of times,made changes here and there.Yes! indeed it gives me the errors you have mentioned, hence the post!
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually fromfile and tofile are declared within the first try block and then you try to access them in the second try block where they are not in scope any more...
One try-catch block should suffice.
 
Tanuja Vaid
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Val,
It Worked!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic