Tested in Solaris and Linux for bash,csh and ksh shells.
RandomAccessFile.writeBytes() writes and reads a file created under umask 777.
Set umask to 777 , so that any file created will have 000 permissions.
Read and write methods in java.io should check file permissions of a file before reading and writing (or) File.canRead(),File.canWrite() and File.canExecute() return true, for the situations like this one otherwise it seems to be odd writing to a file for which File.canWrite() returns false.
<CODE>
import java.io.*;
import static java.lang.System.out;
class Test8 {
public static void main(String ... args) throws IOException {
byte b[] = new byte[20];
File f = new File ("raf");
RandomAccessFile raf = new RandomAccessFile(f,"rw");
out.println("can Read "+f.canRead());
out.println("can Write "+f.canWrite());
out.println("can Execute "+f.canExecute());
out.println("Writing Hello ...");
raf.writeBytes("Hello ");
out.println("done.");
out.println("Writing World ...");
raf.writeBytes("World");
out.println("done.");
out.print("reading ...");
raf.seek(0);
raf.read(b);
out.println(new String(b));
raf.close();
}
}
</CODE>
<Result>
bash-3.00$ uname -a
SunOS client24 5.10 Generic sun4u sparc SUNW,Ultra-60
bash-3.00$ umask -S
u=,g=,o=
bash-3.00$ java Test8
can Read false
can Write false
can Execute false
Writing Hello ...
done.
Writing World ...
done.
reading ...Hello World
bash-3.00$
</Result>
RandomAccessFile.writeBytes() writes and reads a file created under umask 777.
Set umask to 777 , so that any file created will have 000 permissions.
Read and write methods in java.io should check file permissions of a file before reading and writing (or) File.canRead(),File.canWrite() and File.canExecute() return true, for the situations like this one otherwise it seems to be odd writing to a file for which File.canWrite() returns false.
<CODE>
import java.io.*;
import static java.lang.System.out;
class Test8 {
public static void main(String ... args) throws IOException {
byte b[] = new byte[20];
File f = new File ("raf");
RandomAccessFile raf = new RandomAccessFile(f,"rw");
out.println("can Read "+f.canRead());
out.println("can Write "+f.canWrite());
out.println("can Execute "+f.canExecute());
out.println("Writing Hello ...");
raf.writeBytes("Hello ");
out.println("done.");
out.println("Writing World ...");
raf.writeBytes("World");
out.println("done.");
out.print("reading ...");
raf.seek(0);
raf.read(b);
out.println(new String(b));
raf.close();
}
}
</CODE>
<Result>
bash-3.00$ uname -a
SunOS client24 5.10 Generic sun4u sparc SUNW,Ultra-60
bash-3.00$ umask -S
u=,g=,o=
bash-3.00$ java Test8
can Read false
can Write false
can Execute false
Writing Hello ...
done.
Writing World ...
done.
reading ...Hello World
bash-3.00$
</Result>