SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Java Question

  1. #1
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Java Question

    What do I have to do to get Java to recognize the file "data.txt" that is in the same directory as the class containing this code:
    Code:
    BufferedReader in = new BufferedReader(new FileReader(data.txt));
    I'd like to set it up so that it works no matter what directory the files are in so long as they are in the same directy. Any clues?

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    The easiest way is to put the full directory structure in there ex. C:\data\data.txt

    I am trying to remember how to edit the Autoexec.bat to make Java read everything from its own directory....

  3. #3
    SitePoint Wizard dominique's Avatar
    Join Date
    Dec 2000
    Location
    orbis terrarum
    Posts
    1,523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, that's how I have it now but I cannot leave it this way because I have to submit this work to the teaching assistant for correction and I have no way of knowing where she will put the files or on what OS for that matter.

    Is there some type of command that will detect what directory the class file is in? I know System.getProperty("user.home") gets the users home directory (C:\windows\) in Windows. Is there a way I can change "user.home" to something that will detect the current directory?

    I don't see why if you just put data.txt it doesn't look for the file in the same diectory, that's pretty dumb.


Bookmarks

Posting Permissions

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