Java programmeerimise konspekt
}
Andmete lugemine failist baithaaval
try {
FileInputStream voog = new
FileInputStream
("andmed.bin");
System.out.println ("Baidid on: ");
int bait;
while ((bait = voog.read()) != -1) {
System.out.print (Integer.toHexString
(bait) +
" ");
}
voog.close();
System.out.println();
}
catch (IOException e) {
System.out.println ("S/V viga: " + e);
}
Faili lugemine baitmassiivi
try {
FileInputStream p = new FileInputStream
("tekst.txt");
byte[] sisu = new byte [p.available()];
p.read (sisu);
p.close();
// siin on meil kogu fail baitmassiivina
System.out.write (sisu);
}
catch (IOException e) {
System.out.println ("S/V viga: " + e);
}
Kataloogi sisu lugemine
File f = new File ("tmp"); // suval. kat.