package stream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class WriteDataDemo {
public WriteDataDemo() {
}
public static void main(String[] args) throws IOException {
// write the data out with FileOutputStream
// buat file
File outputFile = new File("latihan.txt");
// buka stream
FileOutputStream out = new FileOutputStream(outputFile);
System.out.println(outputFile.isFile());
// sediakan data string
String testOutput ="This is an exercise to write data to a file with FileOutputStream," ;
System.out.println(outputFile.getAbsoluteFile());
/* Cara 1 : tulis data ke stream
for(int i=0;i
out.write((byte)testOutput.charAt(i));
}
*/
/*Cara 2 : tulis data ke stream*/
out.write(testOutput.getBytes());
//untuk melihat
// tutup stream
out.close();
}
}
Tidak ada komentar:
Posting Komentar