package stream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Document {
private File file;
private String teks="";
public Document() {
}
public Document(File File) {
setFile(file);
}
public Document(String FileName) {
File tempFile = new File(FileName);
setFile(tempFile);
}
public void Baca( ) throws IOException {
FileInputStream stream = new FileInputStream(getFile());
int result;
while ((result = stream.read()) != -1) {
setTeks(getTeks() + (char) result);
}
stream.close();
}
public void Simpan() throws IOException {
FileOutputStream stream = new FileOutputStream(getFile());
stream.write(getTeks().getBytes());
stream.close();
}
/**
* @return the file
*/
public File getFile() {
return file;
}
/**
* @param file the file to set
*/
public void setFile(File file) {
this.file = file;
}
/**
* @return the teks
*/
public String getTeks() {
return teks;
}
/**
* @param teks the teks to set
*/
public void setTeks(String teks) {
this.teks = teks;
}
}
Tidak ada komentar:
Posting Komentar