FileInputStream
in FileOutputStream
 |
se
uporabljata za branje in pisanje v datoteke; |
 |
za
branje in pisanje imata enake metode kot InputStream in OutputStream; torej
read in write. |
import java.io.*;
class testCopy {
public static void main (String argv[]) {
int c;
FileInputStream fin;
FileOutputStream fout;
try {
fin=new FileInputStream("lala");
fout=new FileOutputStream("lala-copy");
while ((c=fin.read())!=-1) { // beremo do konca datoteke
System.out.println((char)c);
fout.write(c); // pišemo v drugo datoteko
}
}
catch (FileNotFoundException e) {
System.out.println("Ne morem odpreti datoteke " + e.getMessage());
}
catch (IOException e) {
System.out.println("Napaka pri branju " + e.getMessage());
}
catch (Exception e) {
System.out.println("Neka druga napaka");
}
}
}