• Post Reply Bookmark Topic Watch Topic
  • New Topic

which method to know my location of txt file?  RSS feed

 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a txt file, located in c:/test/

the exact path is c:/test/abc.txt

and i want to write something to abc.txt

which method to get exact location ?

i have some code like this :
----------------------
String outputFileName = method_to_get_filepath

FileOutputStream out = new FileOutputStream(outputFile);

out.write(b);
out.close();
----------------------
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok..now i realised that i can just straight away put like this:

FileOutputStream out= new FileOutputStream("etasks.txt");

--------
But what if i want full path like c:\test\etasks.txt???
 
Joe Ess
Bartender
Posts: 9436
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried passing the full path as an argument to the FileOutputStream constructor? I'd think that would work. If it doesn't, you can always create a File instance for the full path and use that to initalize FileOutputStream.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileOutputStream accepts full path.

If the path is written in Java code as String literal, \ must be escaped as \\ . (This holds only for \ not for /.)


[ August 31, 2006: Message edited by: Vlado Zajac ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!