Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- public class GhiTiepFile {
- public static void main(String[] args) {
- String duonglink = "/home/thieumao/Desktop/GhiTiepFileDo.txt";
- String themvao = "Noi dung can ghi";
- BufferedReader br = null;
- BufferedWriter bw = null;
- try {
- br = new BufferedReader(new InputStreamReader(new FileInputStream(
- duonglink)));
- String line = "";
- String newLine = "";
- while ((line = br.readLine()) != null) {
- newLine = newLine + line + "\n";
- }
- bw = new BufferedWriter(new FileWriter(duonglink));
- newLine = newLine + themvao;
- bw.write(newLine);
- bw.flush();
- } catch (FileNotFoundException ex) {
- JOptionPane.showMessageDialog(null, "Duong dan bi sai");
- System.exit(0);
- } catch (IOException ex) {
- Logger.getLogger(GhiTiepFile.class.getName()).log(Level.SEVERE,
- null, ex);
- } finally {
- try {
- bw.close();
- br.close();
- } catch (IOException ex) {
- Logger.getLogger(GhiTiepFile.class.getName()).log(Level.SEVERE,
- null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment