Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File not found exception  RSS feed

 
sam liya
Ranch Hand
Posts: 1271
  • Mark post as helpful
  • send pies
  • 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();
}
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!