Example Application: Reader (FileReader) and Write (FileWriter) files.
Imports
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
Check file exists
File file = new File(FILE);
if (file.exists()) {
//TODO
} else {
//TODO
}
String FILE = "YOUR_LOG.log";
FileReader reader = new FileReader(FILE);
BufferedReader buffer = new BufferedReader(reader);
String line = null;
while ((line = buffer.readLine()) != null) {
//TODO
System.out.printf("%s\n", line);
}
buffer.close();
See the implementation: project
Imports
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
Check file exists
String FILE = "YOUR_LOG.log";
File file = new File(FILE);
if (file.exists()) {
//TODO
} else {
//TODO
}
String content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
String FILE = "YOUR_LOG.log";
FileWriter writer = new FileWriter(FILE);
BufferedWriter buffer = new BufferedWriter(writer);
buffer.write(content);
System.out.println("Success! You file is saved!");
buffer.close();
See the implementation: project
- IOException