Results 1 to 9 of 9
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default new File(Project's folder) how do I get that?

    Hi, I need the File to be the project's folder, and I can't seemed to figure how to do that...

    If I write in the File folder's name that located in that project, it works, but if I will I can't get the project's folder it's self...
    Help?
    WARNING I am Russian so it's possible that I wont understand you correctly...

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: new File(Project's folder) how do I get that?

    If you're writing an application then do you really want to be thinking in terms of a project folder?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: new File(Project's folder) how do I get that?

    I am writing server for a personal use, without exporting it, so yeah..
    WARNING I am Russian so it's possible that I wont understand you correctly...

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: new File(Project's folder) how do I get that?

    Please explain in more detail. What exactly are you trying to do and why?

  5. #5
    SJF
    SJF is offline Senior Member
    Join Date
    Oct 2012
    Posts
    108
    Rep Power
    0

    Default Re: new File(Project's folder) how do I get that?

    Java Code:
           File nf = new File("");
           System.out.print(nf.getAbsolutePath());
    I don't know if this is what you mean, but this will tell you where you are.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: new File(Project's folder) how do I get that?

    Quote Originally Posted by SJF View Post
    Java Code:
           File nf = new File("");
           System.out.print(nf.getAbsolutePath());
    I don't know if this is what you mean, but this will tell you where you are.
    If he's looking for the jar's location, your method may fail if it is called from a different directory. For example, compare the results obtained in the following code, especially if jar'd and called from another location:

    Java Code:
    import java.io.File;
    
    import javax.swing.JOptionPane;
    
    public class TestWhereIAm {
       public static void main(String[] args) {
          String whereIAmString = "using user.dir: " + System.getProperty("user.dir") + "\n";
          File nf = new File("");
          whereIAmString += "using getAbsolutePath: " + nf.getAbsolutePath() + "\n";
          whereIAmString += "using protection dom: " + TestWhereIAm.class.getProtectionDomain().getCodeSource().getLocation();
          
          JOptionPane.showMessageDialog(null, whereIAmString);
       }
    }

  7. #7
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: new File(Project's folder) how do I get that?

    Sorry for a long no response.

    Well when I use File nf = new File(""); it gives me an error for some reason... and if I will use File nf = new File("bin/"); it will work perfectely.. (I've placed the files to the bin folder when I tried to test File nf = new File("bin/");)
    WARNING I am Russian so it's possible that I wont understand you correctly...

  8. #8
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: new File(Project's folder) how do I get that?

    Java Code:
    File f = new File(".");
    In most OSes '.' is "current directory".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    3

    Default Re: new File(Project's folder) how do I get that?

    Ohhhh thanks! Now it's good!
    WARNING I am Russian so it's possible that I wont understand you correctly...

Similar Threads

  1. Replies: 0
    Last Post: 11-12-2011, 01:26 PM
  2. STRUTS 2 project folder hierarchy
    By buyapentiumjerk in forum Web Frameworks
    Replies: 3
    Last Post: 06-18-2011, 05:50 PM
  3. How to Add Poratl Project Folder to Eclipse ?
    By gb.rashu in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-07-2010, 08:34 AM
  4. How to create an access folder for a project in the Jboss server
    By satya kishore in forum Web Frameworks
    Replies: 0
    Last Post: 02-09-2009, 12:31 PM
  5. Can we Add lib folder insdie Project JAR file ?
    By mahendra.athneria in forum AWT / Swing
    Replies: 1
    Last Post: 01-30-2009, 05:51 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
  •