aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes RandomAccessFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "RandomAccessFile" Watch "RandomAccessFile" New topic
Author

RandomAccessFile

amrit singh
Ranch Hand

Joined: Nov 03, 2000
Posts: 42
constructing like
RandomaccessFile raf=new RandomAccessFile("xxx","rw");
what will happen if the file xxx is read-only and we try to write.
if the file xxx exist it is opened in append mode true or false
Also if we wrap a string fxx
as
File f=new File("fxx");
it will compile but when run it will throw exception if fxx
doesnot exist true or false
if true where the file fxx is looked for in current directory or
else
pls clarify my confusion.or i am missing something.
Munish Dabra
Greenhorn

Joined: Jan 07, 2001
Posts: 7
--------------------------------------------------------------------------------
constructing like
RandomaccessFile raf=new RandomAccessFile("xxx","rw");
what will happen if the file xxx is read-only and we try to write.
if the file xxx exist it is opened in append mode true or false
Also if we wrap a string fxx
as
File f=new File("fxx");
it will compile but when run it will throw exception if fxx
doesnot exist true or false
if true where the file fxx is looked for in current directory or
else
pls clarify my confusion.or i am missing something.
-----------------------------------------------------------------------
Ans. File f=new File("fxx");
Yeah if there is n't any such file exists then at run time iit will throw an IOException.
ya amrit ofcourse fxx file is looked in current directory by default.
if u wanna this it to look in some particular directory.then u have to use a different
constructor of File-----
File f=new File(String path,String filename)
or
File f=new File(File dir , String filename)
here plz note that File object can be a directory or file.ucan check it by
calling boolean method of File class
boolean isFile() or isDirectory().
i hope it will serve the purpose.
------
Munish Dabra
------
nan sh
Ranch Hand

Joined: Jan 05, 2001
Posts: 167
answer your first question;
RandomaccessFile raf=new RandomAccessFile("xxx","rw");
and if the file xxx is read-only and we try to write,
then FileNotFoundException is thrown.
also for random access file, all read or write to current
position, u can use seek() to search, so there is no such
thing "append mode."


Have you tried this Mock Exam Testing Engine yet?<br /><a href="http://www.mycgiserver.com/~nan111/index.html" target="_blank" rel="nofollow">www.mycgiserver.com/~nan111/index.html</a>
Zheng Huang
Ranch Hand

Joined: Dec 20, 2000
Posts: 49
To your 2nd q. No exception will be thrown. run code below.
import java.io.*;
import java.awt.*;
public class TestApp {
public static void main(String argv[]) {
File f;
f=new File("fxx");
System.out.println(f.exists() + " " + f.isFile());
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RandomAccessFile