Re: Find out really (!) the path / getParent() not working



Hi Lars

What you are doing is correct the only thing is that you are getting
the relative path. for ex.

File fileName = new File("abc.java");
String path = fileName.getParent(); //path = null

File fileName = new File("D:/test/abc.java");
String path = fileName.getParent(); //path = D:/test

Now if you want to get absolute path from relative path you can do
this.

File fileName = new File(args[0]);
fileName = fileName.getAbsolutePath();
fileName = new File(fileName);
String path = fileName.getParent();

I hope this will solve your problem.
If there is anything more, let me know.

-Alan
fileName = new File()

.



Relevant Pages

  • Re: absolute path to relative path conversion
    ... you give as you are effectively just after the filename: ... You could walk from you absolute path to the root of your drive and then ... walk down the path to your file, building the relative path as you go along. ... > Sorry for being so vague Rob ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: lock on filename for XmlDocument.Save?
    ... sometimes absolute path and sometimes relative path. ... XmlDocument.Save with a filename attempts to open the file in Create mode for Writing with only Read sharing. ... if you don't really care that the second simultaneous Save is going to destroy the data from the first Save, you could just do a lock the XmlDocument.Save function call, which will enforce only one save at a time, or you could do a bit more complicated logic if you do care that you are overwriting an existing file, which will happen once the first Savecompletes. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: MSXML: Loading from file
    ... The sample Andrey links to hopefully should get you started. ... warning in your sample is that you're using the relative path "filename.xml" ... >> the filename to the load function of a IXMLDomDocument. ... >> The problem is that VariantString doesn't exit on the Pocket PC. ...
    (microsoft.public.pocketpc.developer)
  • Re: absolute pathnames (with bash)?
    ... On Thu, 03 Apr 2003 at 20:21 GMT, Michael A. Miller wrote: ... > That only works if I start with a relative path. ... > filename is '/'. ...
    (comp.unix.shell)
  • lock on filename for XmlDocument.Save?
    ... I'm calling XmlDocument.Save with a filename that often varies. ... sometimes absolute path and sometimes relative path. ... get a re-entrant save to the same filename, ...
    (microsoft.public.dotnet.languages.csharp)