dcsimg
Problem using FileReader to read files in a sibling folder
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Aejaz_Sheriff
Posted On:   Tuesday, August 28, 2001 12:13 PM

I have a text file in a sibling directory i.e /project/java/readfile.class /project/files/somefile.txt To Read the file this is my code File f = new File ("/project/files/readfile.txt"); /* System.out.println(f.getName()); returns NullPointerException */ System.out.println(f.getAbosultePath()); /* System.out.println(f.getName()); returns NullPointerException */ File f = new File("files/readfile.txt"); /* System.out.println(f.getName()); returns readfile.txt */ System.out.println(f.getAbosultePath())   More>>


I have a text file in a sibling directory i.e



/project/java/readfile.class

/project/files/somefile.txt



To Read the file this is my code

			
File f = new File ("/project/files/readfile.txt");

/* System.out.println(f.getName());
returns NullPointerException
*/


System.out.println(f.getAbosultePath());

/* System.out.println(f.getName());
returns NullPointerException
*/


File f = new File("files/readfile.txt");

/* System.out.println(f.getName());
returns readfile.txt
*/


System.out.println(f.getAbosultePath());

/* returns C:projectjavafilessomefile.txt
*/


/* But FileReader Constructor returns
java.io.FileNotFoundException: somefile.txt
*/
FileReader fr = new FileReader(f);




I am confused any help on this would be greatly appreciated



Cheers
Aejaz

   <<Less
About | Sitemap | Contact