• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writting a String to a file

 
Garandi Garandi
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9314
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic