Opening USB flash in Java as a RandomAccessFile has problems with seek, length and setLength methods. Small example of code:
try {
RandomAccessFile raf = new RandomAccessFile("\\\\.\\G:", "r");
raf.seek(10);
raf.setLength((long) 0);
System.out.println(raf.length());
}
catch (FileNotFoundException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
Or there is another problem. This code throws FileNotFoundException, but i can open this path in Windows and see files:
try {
File file = new File("G:\\");
RandomAccessFile raf = new RandomAccessFile(file, "r");
}
catch (FileNotFoundException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
What can i do to solve this problem? It's necessary to open flash device as RandomAccessFile to work with it using Fat32-lib