• 文件内容替换


    import java.io.*;
    
    public class T {
    
        public static void main(String[] args) {
            try {
                String a = "D:\\.ftl";
                BufferedReader bufReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(a))));//数据流读取文件
    
                StringBuffer strBuffer = new StringBuffer();
                String empty = "";
                String tihuan = "";
                int dd = 37;
                for (String temp = null; (temp = bufReader.readLine()) != null; temp = null) {
                    System.out.println(temp);
                    System.out.println("---------------------------");
                    if (temp.indexOf("yanyan") != -1) { //判断当前行是否存在想要替换掉的字符 -1表示存在
    
                        int i = temp.indexOf("yanyan");
                        tihuan = temp.substring(i, i + 6);
                        empty = "id="a" + dd + "" name="a" + dd + "" value="${scData.a" + dd + "!''}"";
                        temp = temp.replace(tihuan, empty);//替换为你想要的东东
                        System.out.println(temp);
                        dd++;
                    }
                    strBuffer.append(temp);
                    strBuffer.append(System.getProperty("line.separator"));//行与行之间的分割
                }
                bufReader.close();
                PrintWriter printWriter = new PrintWriter("D:/EntNatureDistributionDAO.txt");//替换后输出的文件位置
                printWriter.write(strBuffer.toString().toCharArray());
                printWriter.flush();
                printWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
    
    }
    
  • 相关阅读:
    DataTable轉EXCEL 3/21
    中風預防知識
    unable to convert mysql date/time value to system.data.time 11/14
    win8 获得地理坐标 GIS
    页面嵌套 GIS
    win8 metro 弹出一个部分 GIS
    正则表达式基础 之 ? GIS
    windows phone pivot 开发过程中的使用心得 GIS
    线程不安全 GIS
    线程基础知识 GIS
  • 原文地址:https://www.cnblogs.com/xx2017/p/10975813.html
Copyright © 2020-2023  润新知