How to get the absolute path of a file from the local disk given the file n

how to get the absolute path of a file from the local disk given the file name

// will look for the file at the current working directory
// this is wherever you start the Java application (cound be C: and your
// application is located in C:/myapp, but the working dir is C:/
File file = new File("README.txt"); 
if (file != null && file.exists())
    String absolutePath = file.getAbsolutePath();

Similar Messages

  • When I try to save a new file from numbers, I'm given the error of it can't create a file. why would that be?

    when I try to save a new file from numbers, I'm given the error of it can't create a file. why would that be?

    Try using /Applications/Utilities/Disk Utility to repair file permissions.
    Bob

  • Can't Zap the P-RAM , Can't start from an installer disk with the C-Key...

    Can't Zap the P-RAM , Can't start from an installer disk with the C-Key... or The D-Key for Apple Hardware test or run with the shift Key in Safe Mode!!!
    About a week ago I started to have problems with the Mac after 10.5.6! First the Mac after shut down would restart on its own in 10 to 15 minutes. I read in various forums about some of the 10.5.6 problems. I did a clean reinstall where the Mac created a previous system folder. After this suddenly mail, I-Chat as well as some other programs would open, then close immediately! Since I did not have things backed up because I didn't have a large drive, I dragged my files and apps to another drive and reformatted the drive zeroing out all data and did a fresh new install then brought in the combo 10.5.6 update.The Mac is running correctly but I can't Zap the P-Ram, startup from the Mac OS X installer Dvd with the C key or run Apple Hardware Test with the D key or boot in safe mode with the shift key. I can boot any of the Bootable disks from the start-up Disk in Preferences.
    I went over this with Apple and they suggested I run the Apple Hardware test. It won't run on this machine because I can't boot it with the D- Key. I ran tech Tools and every single thing checks out OK! This Mac has worked great since I got it in I believe Feb or March of 2007.

    Make sure that you don't have firmware password protection enabled. It will prevent some boot key shortcuts from working, like clearing NVRAM, etc. You can disable firmware password protection by booting off the OSX DVD and loading the utility.

  • How to get the absolute path of logicalhost server domain on Windows Sun

    i am reading a file from Xsql Folder, that is located in the logicalhost Sun\AppServer\domains\domain1\applications\j2ee-apps.(IN Sun Application Server)
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    i tried with System.getProperty("com.sun.aas.instanceRoot").
    but i am able to retrive Sun\AppServer\domains\domain1 upto this .i am unable to retrive Sun\AppServer\domains\domain1\applications\j2ee-apps.
    please suggest me how u can get absolute path in sun application server

    Take a look here

  • How to get the absolute path of logicalhost server domain on Windows?

    My logicalhost server domain behaves strangely. I am reading a file from collaboration definiton, that is located in the logicalhost/is/domains/domain1/config folder. I thought, that this folder is used as an application root folder so I can read files like ./file from there. And it worked.
    But then I've installed the domain as a Windows service, restarted the PC. When the domain1 gets started, I get exceptions saying that the file can't be found. Then I restart the domain (in domainmgr.bat) and it works again.
    I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
    And my second question is: Why does this happen?

    The default folder for a Windows Service is the system32 folder contrary to the instance root folder when starting it as a normal process.
    That's the why, haven't tried the how, but you should be able to get the value by calling System.getProperty("com.sun.aas.instanceRoot").
    Hope this helps
    Paul

  • How to get the absolute path of a DTD referenced in an XML?

    Hello!
    My OS is Windows.
    I use "org.apache.xerces.parsers.SAXParser" which implements LexicalHandler to parse XML files. When method "startDTD" starts and "systemId" is got, how can I get the absolute path? Is there any simple way?
    Regards!

    Hi,
    http://forum.java.sun.com/thread.jsp?forum=34&thread=36
    612The methods in the above topic seem to be available when use a DOM parser..

  • Get the absolute path and filename of the file from the command line

    Hi,
    when we run the class we give the command
    java <filename>
    How can I capture the filename given above and get its absolute path inside the
    public static void main(String [] args){}
    args[0] gives me the command line argument after the filename. How do I capture the filename itself from the command line argument and also get that files absolute path
    Thanks

    I don't know of any way to capture the java command input, but there are ways to find out where the application is being run from. (the "absolute path")
    http://forum.java.sun.com/thread.jsp?forum=31&thread=335394

  • Getting the absolute path of the current executing file

    I have a file which will be placed in window and linux environment. It is not good to change the source code in that way:
    String path = "D:\\java\file1.txt"; (Window)
    String path = "/java/file1.txt"; (Linux)
    So I would like to ask how to get the absolute path based on that executing file?
    I referred to the reference in jsp, but I don't know what class and the coding syntax in console environment.
    Thx for any help.

    If you are looking to "get" a file that is located in a directory with (or somewhere under) the class file than use
    myClass.getClass().getResource(<relativePathWithFileFromClass>);  //URL
    myClass.getClass().getResourceAsStream(<relativePathWithFileFromClass>);  //InputStreamAs far as determining which Operating System you are on, there are a number of environment variables that will tell you that, and you can then format your file path accordingly.
    You can use "/" in your path regardless of which OS you are using. You do not have to use "\\" on Windows (excpet maybe inside of a Runtime.exec command string).
    Here is a very small program you can compile and run if you wish to see the list of System Properties available:
    public class ShowProperties {
      public static void main(String[] args) {
        System.getProperties().list(System.out);
    }Just save that to a file (named ShowProperties.java of course) and compile and run it, and you will get a list of your available System Properties and their current values

  • How can you determine the absolute path to a dynamically created NetStream object?

    We are trying to implement video captioning with a freeware component, ccforflash. This requires us to provide an absolute or relative path  to our NetStream object. How can we determine this path in Flash CS5 AS3?
    From the CCforFlashCS5 documentation:
    "2. Object name and path
    Type the name and path.  This is the instance name of the object with which CCforFlashAS3 will synchronize. It must be spelled correctly, since CCforFlashAS3 will query the object with this name for timing information in order to synchronize the captions. The path must also be included; either relative to the CCforFlashAS3 component (i.e. this.parent) or the absolute path from the main level of the movie (root)."

    It would be easier if the NetStream object was created on an easily identifiable place on the timeline. This player has an MVC architecture. The NetStream object is created in a subclass to Model class, which is itself a subclass of the EventDispatcher object. The View class access it via an interface.
    As you can guess, it's not that straightforward to determine where the NetStream object is located on the timeline. This is compounded by the fact that the NetStream object does not have a name property.
    I've tried methods like these, but they only work for the DisplayObject class:
    public static function displayObjectPath( avDisplayObject : DisplayObject ) :String
    var lvPath:String = "";
    do
    if( avDisplayObject.name ) {
    // var obj_name:String = (avDisplayObject.name == 'root1') ? 'root' : avDisplayObject.name;
    if (avDisplayObject.name != 'root1') {
    lvPath = avDisplayObject.name
       + ( lvPath == "" ? "" : "." + lvPath );
    } else {
    trace("displayObjectPath() NO NAME avDisplayObject="+avDisplayObject);
    } while( avDisplayObject = avDisplayObject.parent );
    return lvPath;
    } // displayObjectPath
    private  function showChildren(d:DisplayObjectContainer):void {
    trace("showChildren()");
    if (d.numChildren>0) {
    for (var c:Number = 0; c < d.numChildren; c++) {
    trace("showChildren c=",c," name=",d.getChildAt(c).name);

  • To get the absolute path of a file in JSP

    Hi,
    I want to include a HTML page in a jsp.The path of the jsp should not be hot coded.So that i can get the path from the jsp file i am running and then concat the correspondinghtml file name to the absolute path of the jsp file i am running.What can i do to get the absolute path of the jsp file.

    I dont know if there is a way to get the path of the current jsp - but you sure can get the path to your web application using the ServletContext's getRealPath() method and then if you have stored the html (say x.html) in a folder (called, say 'static') immediately under your application root,
    String contextPath = application.getRealPath("/"); //path to your application ctxt
    String htmlFilePath = contextPath.append("/static/x.html");ram.

  • How to find the absolute path of file  which store in KM foler ?

    Hello everyone:
         We want to develop an ABAP program which can write files into KM folder directly.
         So I need to find the absolute path of file which store in KM folder first, then we can consider the develop solution.
         Is this issue possbile that an ABAP  program write files into KM folder  directly ?
         Is there anybody had done this job ?
    Best Regards,
    Jianguo Chen

    Hi,
    http://forum.java.sun.com/thread.jsp?forum=34&thread=36
    612The methods in the above topic seem to be available when use a DOM parser..

  • How determine the absolute path of the aep-project?

    As in the script to determine the absolute path of the project?

    Try this for the platform-specific path:
    app.project.file.fsName
    or this for the URI path,
    app.project.file.fullName
    Dan

  • Sharepoint Workflow : how to get document full path + file name into variable?

    Hi,
    Anybody knows how to get document full path + file name into a variable in Sharepoint 2010 workflow?
    Example http://sp1:80/InvoiceQueue/Shared Documents/123.pdf
    I am using List Workflow which links to a document library.

    Hi SAMSUNG,
    According to your description, my understanding is that you want to get the full path of a document in a list workflow.
    You can set the variable to the Enconded Absolute URL of the document. The screenshot is my testing. In my testing (in the red area), when the title of a document was equal to the tile of the current item, set a variable to the Enconded Absolute URL of the
    document. I used ‘Log to history list’ to check the value of the variable in Workflow History .
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How to get full package path?

    Hi all.
    My program consists of 2 files:
    1.) run.exe
    2.) classes.zip
    The second (.zip) file contains java classes. How can I gain a full path to any package in this .zip file? I tried
    MyClass.class.getPackage().getName() but it returned only somethig like myPackage.mySecondPackage. But I need full path, something like C:\My program\...
    Many thanks.
    Miso

    I tried
    > MyClass.class.getPackage().getName()
    but it returned only somethig like
    myPackage.mySecondPackage. But I need full
    path, something like C:\My program\...
    Think of it a bit: your jar (or zip) file is stored in, say 'c:\MyPrograms'
    as 'myjar.zip'. What should the path of your class file be then?
    'c:\MyPrograms\myjar.zip\myPackage.mySecondPackage.MyClass'
    wouldn't make any sense would it?
    Leaving out the name of the jar/zip file itself wouldn't make any sense
    either. IOW, the 'absolute path' of a class doesn't make any sense,
    as long as the JVM can find your classes everything is fine.
    kind regards,
    Jos

  • How to avoid giving absolute path?

    Hi
    I have a web application which contains some jsps and servlets and i am running it on Apache Tomcat 4.1. The name of my application is MyApp which contains all the servlets and jsps.
    In order to deploy the application i have placed the MyApp folder in the 'webapps' folder of Tomcat. Now in one of my servlets i.e. 'DirectoryCreator', i am trying to create a folder i.e. 'Directory' in the MyApp folder. The problem is that i dont want to give an absolute path to the File class constructor. The class files of my servlets are in classes folder i.e. MyApp \ Web-INF \ classes.
    I have tried:
    File f = new File("/Directory");
    f.mkdir();but this creates the Directory folder in my C drive.
    Please tell me how i can avoid giving the absolute path.
    Thanks.

    What you want is getSerlvetContext().getRealPath("WEB-INF/NewDir").
    If you're going to put extra data into your webapp you should put it in WEB-INF unless you want it to be avaialble to be served e.g. html files etc.

Maybe you are looking for