Sunday, 15 May 2011

Java absolute file path not giving the desired path -



Java absolute file path not giving the desired path -

i have created folder 'maths' @ /home/vamshi/documents/eval/files/standard6/maths/ , have set files in it. hello.txt, world.txt

now, have used java code traverse directory

system.out.println("directory path :"+path); file f = new file(path); system.out.println("directory abs path :"+f.getabsolutepath()); if( f.isdirectory() ) { string[] subnote = f.list(); for(string filename : subnote) { file tempfile = new file(filename); system.out.println("file path:"+tempfile.getabsolutepath()); } } else { system.out.println("its not directory!"); }

output :

directory path :/home/vamshi/documents/eval/files/standard6/maths/

directory abs path :/home/vamshi/documents/eval/files/standard6/maths

file path:/home/vamshi/workspacenew/server/gui_version_netbeans/server/hello.txt

file path:/home/vamshi/workspacenew/server/gui_version_netbeans/server/world.txt

how possible? how come files within maths directory have netbeans project absolute path?

when create new file using file name, creates file in default directory. in case, file set "/home/vamshi/workspacenew/server/gui_version_netbeans/server/"

instead of giving file name:

file tempfile = new file(filename);

give desired path , file name, so:

file tempfile = new file(path + filename);

this should create file , set desired location.

java file path directory absolute-path

No comments:

Post a Comment