Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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

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!!!
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic