Rabu, 21 Desember 2011

Stream_Kelas WriteDataDemo

package stream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class WriteDataDemo {

    /** Creates a new instance of 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);

        String NIM = "105314007";
        String Nama = "James";
        String IdKoleksi = "001";
        String Judul = "laskar Pelangi";

         // sediakan data string
        String txt = NIM + "\t" + Nama + "\n" + IdKoleksi + "\t" + Judul + "\n";
        // menulis data ke stream
        out.write(txt.getBytes());

        System.out.println(outputFile.getAbsolutePath());
        System.out.println(outputFile.isDirectory());
        System.out.println(outputFile.isFile());
   
        out.close();
    }
}

Tidak ada komentar:

Posting Komentar