Results 1 to 3 of 3
  1. #1
    rru96 is offline Senior Member
    Join Date
    Sep 2012
    Posts
    108
    Rep Power
    0

    Default Remember File Structure on subsequent openings

    I have a program I am working on, and have been using the following code:
    Java Code:
    private void checkQInstall(){
    		try {
    			qs = new File("C:\\MEMORYGAME\\q.bin");
    			in = new BufferedReader(new FileReader(qs));
    		} catch (FileNotFoundException e) {
    			System.out.println("CALLED");
    			dir1 = new File("C:\\MEMORYGAME\\");
    			dir1.mkdirs();
    			
    			try {
    				out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("C:\\MEMORYGAME\\q.bin")));
    				
    			} catch (FileNotFoundException e1) {
    				System.out.println("FAILED TO CREATE FILE STRUCTURE");
    				System.exit(0);
    			}
    		}
    	}
    Now my main issue is I am working on a project that could be used on a variety of systems. I understand that Java is designed for flexibility among OS's and that the way I have coded is designed for a Windows system (afaik). Can someone help point me in a direction on how to retain an installation directory so that on subsequent openings, the program knows where to open the file, without it being platform dependent. I have never used a mac. Thank you
    Last edited by rru96; 03-12-2014 at 11:51 PM.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,086
    Rep Power
    4

    Default Re: Remember File Structure on subsequent openings

    You can find the directory where the program is started from using System.getProperty("user.dir"). From there you can build your paths.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    rru96 is offline Senior Member
    Join Date
    Sep 2012
    Posts
    108
    Rep Power
    0

    Default Re: Remember File Structure on subsequent openings

    Thank you very much.

Similar Threads

  1. Replies: 0
    Last Post: 11-12-2011, 02:26 PM
  2. data file structure
    By Nicholas Jordan in forum Advanced Java
    Replies: 2
    Last Post: 01-07-2009, 05:16 AM
  3. writing/reading a Structure to/from a file
    By Farzaneh in forum New To Java
    Replies: 1
    Last Post: 08-31-2008, 03:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •