Results 1 to 8 of 8

Thread: file path

  1. #1
    Arsench is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default file path

    Hello all, Im very very new in java and need a help please.
    I have a makefile in the unix system that doing many functions and one of them, creating a file.txt.I want to create a code in the java file that can copy the full path of that file that will created.

    so for example.
    when creating test.txt so the code will print out the path of that test.txt file



    am I explaind good?:(

    thank you

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    The File class has several methods that return different paths to a file.
    I'm not sure what you are asking.
    Is the java program to create the file instead of makefile? How will the java program get the path to where it should create the file?
    If the java program is NOT creating the file, is it supposed to search for where the file was created? How will it get the name of the file to search for? What if 2 files with the same name?

  3. #3
    Arsench is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    thank for your replay, there are only one file with that name, I mean that, when the makefile executing, in that moment execute the java file for search that file.sorry for my bad explain.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    execute the java file for search
    To search a folder and sub folders you'll also need the File list() method.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Do you want to create a file through the application and find the complete file path? Better to explain it more if I'm wrong.

  7. #7
    Arsench is offline Member
    Join Date
    Oct 2008
    Posts
    4
    Rep Power
    0

    Default

    you are right Eranga:) I want to create a file through the application and find the complete file path

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    So in simple way, why don't you do this.

    Java Code:
            File file = new File("C:\\Temp\\Temp.txt");
            
            try {
                if(!file.exists())
                    file.createNewFile();
            }
            catch(IOException ex) {
            }
            
            System.out.println(file.getAbsolutePath());
    Make sure that drive C have a folder name Temp. Because in this way you cannot create folders.

    Can you show your complete code.

Similar Threads

  1. Load class file which resides in local path c:\
    By praveen.kb in forum Advanced Java
    Replies: 2
    Last Post: 08-12-2008, 01:55 PM
  2. Specify path
    By borgrodrick in forum Eclipse
    Replies: 1
    Last Post: 02-12-2008, 11:03 PM
  3. Regular expression for file path
    By ravian in forum New To Java
    Replies: 3
    Last Post: 01-25-2008, 08:24 PM
  4. Replies: 5
    Last Post: 07-31-2007, 04:22 PM

Posting Permissions

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