This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Writting a String to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writting a String to a file" Watch "Writting a String to a file" New topic
Author

Writting a String to a file

Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
I have a String to write it to a file.
I have the following code.

myFile is in the same dir as the sourcefile.java.
How to give relative path, instead of full path name?
Thank you in advance
Garandi
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

Give the File constructor the relative path (which the documentation referrs to as a pathname):

A pathname, whether abstract or in string form, may be either absolute or relative. An absolute pathname is complete in that no other information is required in order to locate the file that it denotes. A relative pathname, in contrast, must be interpreted in terms of information taken from some other pathname. By default the classes in the java.io package always resolve relative pathnames against the current user directory. This directory is named by the system property user.dir, and is typically the directory in which the Java virtual machine was invoked.

java.io.File


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writting a String to a file
 
Similar Threads
Dynamically Creating Files......
Looping through BufferedReader Class
Relative Addressing for .txt Files
Creating a sub sub directory
Absolutepath vs Canonicalpath