• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Files

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
1)What is the effect of path name semantics like "/" in unix and
"\" on windows while creating Files??
2) What is meant by naviagation and non-navigation methods of File class?
3) If i open an existing file in "rw" mode, and start writing will it append or overwrites??
- Thanks.
[This message has been edited by Doit (edited August 15, 2000).]
[This message has been edited by Doit (edited August 15, 2000).]
 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more doubt..
While constructing an instance of a File using constructor File(File dir,String subpath) , the File can be a directory or a file.
If the File is a file, what would be the subpath???
Hope u got me..
- Thanks
 
Rancher
Posts: 241
Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure if I know exactly what you mean on some of these, but here are my answers:
1) You just use whichever one is appropriate; for example, on a Unix machine, use the forward slash in the name string.
2)The File class doesn't have these methods. I don't really recall seeing them either
3)It will overwrite. I dealt with this in a recent program by using something like raf.seek(raf.length()); both numbers are longs so it works out ok.
eric b.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Doit,
I have few answers for ur question.
1)Backslash character is the escape character in Java strings. The Java convention is to use the UNIX and URL-style forward slash for path separators. So, u should use \\ for Windows-style pathnames. C:\\window\\... But if u use a forward slash(/) on a Windows version of Java, the path will still resolve correctly.
2)In my view, RHE means navigation methods as methods which navigate thru the file directory tree hierarchy such as getAbsolutePath, getParent(), etc. Non-navigation methods are such as canRead, canWrite, length, etc. which does not need to navigate thru the directory hierarchy.
3)If u open an existing file in "rw" mode and start writing into it, it will begin overwriting the file. To append to the file, we should explicitly call seek() method by passing the length of the file as argument, so that it will place the pointer at the end of the file.
4)Acc. to RHE, the first argument in the constructor new File(File dir, String subpath); can be directory or file, but when I tried to execute by passing filename to the first argument and the second argument as empty string, there is no effect on the file when I write to it.
Hope this can help u,
Kiran
 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Kiran. Well said.

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for 4), this is what API says
File public File(File parent, String child)
Creates a new File instance from a parent abstract pathname and a child pathname string.
If parent is null then the new File instance is created as if by invoking the single-argument File constructor on the given child pathname string.
Otherwise the parent abstract pathname is taken to denote a directory, and the child pathname string is taken to denote either a directory or a file.
[This message has been edited by Harry Chawla (edited August 28, 2000).]
 
Let's get him boys! We'll make him read this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic