wood burning stoves
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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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

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
Joe Ess

Joined: Oct 29, 2001
Posts: 9150

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.


[How To Ask Questions On JavaRanch]
It is sorta covered in the JavaRanch Style Guide.
subject: Writting a String to a file
jQuery in Action, 3rd edition