baca tulis bahasa java


sedikit catatan singkat nan sederhana tentang baca tulis dalam java

membuat file bernama xxx.txt

// create file
String file = "xxx.txt";
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
PrintWriter localWriter = new PrintWriter(writer);
localWriter.print(value);
localWriter.close();
} catch (IOException e) {
log.error("IOException in write file : "+e.getMessage());
}

membaca file xxx.txt

try {
// read configuration from file
String file = "xxx.txt";
BufferedReader reader = new BufferedReader(new FileReader(file));
String value = reader.readLine();
reader.close();
} catch (IOException e) {
log.error("IOException in read file : "+e.getMessage());
}

satu lagi, cara menghapus file xxx.txt

String file = "xxx.txt";
boolean success = (new File(file)).delete();
if (!success) {
System.out.println("delete file failed");
}

jangan lupa untuk import package java.io.*

😀

About esdynoa

aq adalah orang yang pengen ikut berpartisipasi dalam hiruk pikuk kehidupan maya moga aja dengan membuat blog ini aq bisa lebih serius untuk belajar dan selalu bersemangat :D
This entry was posted in berbagi, koding and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s