21 Desember 2011

String_1


package string;


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


public class Dokumen {


    File file;
    String teks = "";


    public Dokumen(File file) {
        this.setFile(file);
    }
    public Dokumen(String fileName) {
        File tempFile = new File(fileName);
        setFile(tempFile);
    }
    Dokumen() {
    }
   public File getFile() {
        return file;
    }
    public void setFile(File file) {
        this.file = file;
    }
    public String getTeks() {
        return teks;
    }
    public void setTeks(String teks) {
        this.teks = teks;
    }
    public void baca() throws FileNotFoundException, IOException {
        FileInputStream stream = new FileInputStream(file);
        int result = 0;
        while ((result = stream.read()) != -1) {
            teks = teks + (char) result;
        }
    }
    void simpan() throws FileNotFoundException, IOException {
        FileOutputStream stream = new FileOutputStream(file);
        stream.write(teks.getBytes());
        stream.close();
    }
}





Tidak ada komentar:

Posting Komentar