INPUT STREAM:
public class TestFileInputStream {
public static void main(String[] args) throws FileNotFoundException, IOException {
// buat file
File test = new File("latih.txt");
// buat stream
FileInputStream in = new FileInputStream(test);
// baca stream
String result = new String();
int c;
while ((c = in.read()) != -1) {
result = result + (char) c;
}
// tutup stream
in.close();
System.out.println("result " + result);
}
}
INPUT STREAM:
public class TestFileOutputStream {
public static void main(String[] args) throws FileNotFoundException, IOException {
// buat file
File test = new File("latih.txt");
// buat stream
FileOutputStream out = new FileOutputStream(test);
// tulis stream
String data = "hello world";
out.write(data.getBytes());
// tutup stream
out.close();
}
}
0 comment(s):