Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package xulyfile;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- /**
- *
- * @author Thieu Mao
- */
- public class XuLyFile {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- XuLyFile xlf = new XuLyFile();
- }
- public XuLyFile() {
- String strLeft, strRight, strCenter;
- strLeft = "<string1>";
- strRight = "<string2>";
- String[] strData = new String[100];
- int i = 0;
- File f = new File("vanban.txt");
- try {
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- while ((strCenter = br.readLine()) != null) {
- strCenter = strLeft + " " + strCenter + " " + strRight;
- strData[i] = strCenter;
- i++;
- }
- br.close();
- fr.close();
- } catch (Exception ex) {
- System.out.println("Loi doc file!");
- }
- f = new File("vanban.txt");
- try {
- FileWriter fw = new FileWriter(f);
- BufferedWriter bw = new BufferedWriter(fw);
- for (int j = 0; j < i; j++) {
- System.out.println(strData[j]);
- bw.write(strData[j] + "\n");
- }
- bw.close();
- fw.close();
- } catch (Exception e) {
- System.out.println("Loi ghi file!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment