Kalo yg satu ini, buat ngebaca isi yg ada di notepad kita, melalui aplikasi java kita :
package testjeni;
import java.io.*;
/**
*
* @author Mothed
*/
public class ReadFile {
public static void main(String args[]) throws IOException {
System.out.println("What is the name of the file to read from?");
String filename;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
filename = br.readLine();
System.out.println("Now reading from " + filename + "...");
FileInputStream fis = null;
try {
fis = new FileInputStream(filename);
} catch (FileNotFoundException ex) {
System.out.println("File not found.");
}
try {
char data;
int temp;
do {
temp = fis.read();
data = (char) temp;
if (temp != -1) {
System.out.print(data);
}
} while (temp != -1);
} catch (IOException ex) {
System.out.println("Problem in reading from the file.");
}
}
}
contoh penulisannya gini : direktori yg kalian kehendaki:/nama file yg mau kalian baca
C:/bijak.txt
*INGET, file yg bisa dibaca cuma dengan format txt!
Selamat mencoba :D
Read File
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar