View Single Post
  #2 (permalink)  
Old 08-07-2007, 06:53 AM
coco coco is offline
Member
 
Join Date: Jul 2007
Posts: 39
coco is on a distinguished road
Looking at your code...it does seem that you have specified a location of where the file should be saved...or it should be written.

In other words...if you do not explicitly specify a location...the file will be created and saved in the same directory of where the write class is located.

If you want to explicitly specify a location...the best way to do it...is to write an instance of the File class which would encapsulate the directory that you wish to write in. Then, create another instance of the File class which would encapsulate the file that you wish to write to.

Here is an example. In this example, I am going to create a file instance that represents the user's home directory.

Code:
File directory = new File( System.getProperty( "user.home") );
if you are using Windows XP...the user's home directory would be
C:\Documents and Settings\user_name

If you are using Linux..the user's home directory would be.
/home/user_name

Assuming that the following directory structure exists in your home directory MyDocuments -> Java -> CS211 -> lab9 -> persist, we could re-write the directory instance to encapsulate that directory....regardless of what operating system you are using.

Code:
File directory = new File( System.getProperty( "user.home") + File.separator + "Java" + File.separator + "CS211" + File.separator + "lab9" + File.separator + "persist" );
Here is the best part...now you can create an instance of the File class that should encapsulate the file that you wish to write to.

Code:
File file = new File( directory, "Inv.dat" );
now...print out the path to the file just to be sure that is is located where you want to be.

Code:
System.out.println( "Path: " + file.getAbsolutePath() );
Reply With Quote