Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

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!!!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic