regex - How to get to a file by passing relative path in java? -


i trying understand "how file passing relative path of file or folder?" . here example:

code:

  public class somex {     public static void main {        string filename = system.getproperty("user.dir");   <---this gives me path current working directory.        file file = new file(filename + "../../xml_tutorial/sample.xlsx" );        system.out.println(file.getcanonicalpath());         <---this gives me path file residing in folder called "xml_tutorial".      }   }      >>>>  

here, know file location able pass correct relative path. and, managed print file path. have deleted "sample.xlsx" , executed above code; no failing gives me path name , same path when file exists (i.e. before deleting). how possible ? expecting exception here. why not throwing exception ?

two, want use regular expression file name, such as: "../../xml_tutorial/samp.*". doesn't job , gives me ioexception. why not able identify file sample.xlsx ? (note: when file exist , 1 hundred precent sure there 1 file name "sample.xlsx")

i have deleted "sample.xlsx" , executed above code; no failing gives me path name , same path when file exists (i.e. before deleting). how possible ? expecting exception here. why not throwing exception ?

file doesn't care whether file exists. resolves path. there's no need file exist in order take path

/home/tjc/a/b/c/../../file.txt

...and turn canonical form

/home/tjc/a/file.txt

if want know whether file on path exists, can use exists() method.


on second, unrelated question:

two, want use regular expression file name, such as: "../../xml_tutorial/samp.*". doesn't job , gives me ioexception. why not able identify file sample.xlsx ?

there's nothing in file documentation saying supports wildcards. if want searches, you'll want use list(filenamefilter) or listfiles(filenamefilter) , filenamefilter implementation, or listfiles(filefilter) , filefilter implementation.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -