String name = "/dev/tty";
if (argv.length > 0) {
name = argv [0];
}
FileInputStream fis = new FileInputStream (name);
FileChannel channel = fis.getChannel();
try {
System.out.println ("position=" + channel.position());
System.out.println ("Attempting seek 100");
channel.position (100);
System.out.println ("position=" + channel.position());
System.out.println ("Attempting seek 10");
channel.position (10);
System.out.println ("position=" + channel.position());
} catch (Exception e) {
System.out.println ("Caught: " + e);
}
try {
System.out.println ("Attempting truncate");
channel.truncate (100);
} catch (Exception e) {
System.out.println ("Caught: " + e);
}
try {
System.out.println ("Attempting force");
channel.force (true);
} catch (Exception e) {
System.out.println ("Caught: " + e);
}
try {
System.out.println ("Attempting size");
long size = channel.size();
System.out.println ("size=" + size);
} catch (Exception e) {
System.out.println ("Caught: " + e);
}
try {
ByteBuffer bb = ByteBuffer.allocate (10);
System.out.println ("Attempting rel read");
int bytes = channel.read (bb);
System.out.println ("read=" + bytes);
System.out.println ("Attempting abs read");
bb.clear();
bytes = channel.read (bb, 100);
System.out.println ("read=" + bytes);
} catch (Exception e) {
System.out.println ("Caught: " + e);
}