File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Files" Watch "Files" New topic
Author

Files

Doit
Ranch Hand

Joined: Aug 03, 2000
Posts: 169
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

Joined: Aug 03, 2000
Posts: 169
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
Eric Barnhill
Rancher

Joined: Feb 25, 2000
Posts: 226

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.
kiran bayyana
Greenhorn

Joined: Aug 15, 2000
Posts: 17
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

Joined: Aug 03, 2000
Posts: 169
Thank you Kiran. Well said.

Harry Chawla
Ranch Hand

Joined: Jun 03, 2000
Posts: 97
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).]
 
 
subject: Files
 
Threads others viewed
finalize()
Outer class instance
Sleep and Yield.. Am i correct??
Static Initializers.
Loading
MyEclipse, The Clear Choice