• 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

File not found exception

 
Ranch Hand
Posts: 1325
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to copy all files in drive G:\ to other place.
then i get all files form following command.
and i copy every file one by one.
but every time it gives file not found exception.how this happens.


File f=new File("g:\\");
String[] list = f.list();




void copyFile(String f)
{
try{

File f1 = new File(f);
FileReader fr =new FileReader(f);
BufferedReader br =new BufferedReader(fr);

File file2 = new File("E:\\ana\\"+g);
FileWriter fw =new FileWriter(file2);

String size = br.readLine();
while(!(size==null))
{
System.out.println("br.readLine(); "+size);
size=size+System.getProperty("line.separator");
fw.write(size);

size=br.readLine();
}

}
catch(Exception e)
{
e.printStackTrace();
}
}
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a great many things wrong with this code, but one especially bad one is that you never close the file you're writing to. Unless you explicitly close the file, there's no guarantee that the data will ever be written.

Now, if you're seeing a FileNotFoundException, you'll need to tell us what file the message is referring to -- the file you're reading from or writing to?
reply
    Bookmark Topic Watch Topic
  • New Topic