黑帽seo技术有哪些,利用小说网站做本站优化,wordpress文章图片怎么并排,关键词推广优化排名品牌最近因为项目的国际化的需要#xff0c;需要对整个项目的100来个插件做国际化#xff0c;这是一件痛苦的事情#xff0c;因为纯体力劳动。为了省点工作量#xff0c;想着能不能写个程序批处理了#xff0c;减少点工作量#xff0c;于是就有了下面的代码。1.读取指定的(.j…最近因为项目的国际化的需要需要对整个项目的100来个插件做国际化这是一件痛苦的事情因为纯体力劳动。为了省点工作量想着能不能写个程序批处理了减少点工作量于是就有了下面的代码。1.读取指定的(.java)文件复制代码 代码如下:public static String readFile(String path) throws IOException {File f new File(path);StringBuffer res new StringBuffer();String filePathStr f.getPath();System.out.println(获取文件的路径:::::::filePathStr);FileInputStream fis new FileInputStream(f);InputStreamReader isr new InputStreamReader(fis,Charset.forName(GBK)); //以gbk编码打开文本文件BufferedReader br new BufferedReader(isr, 8192 * 8);String line null;int linenum 0;while((linebr.readLine())!null) {linenum ;res.append(line此处可以添加你自己的字符串处理逻辑\r\n);}br.close();return res.toString();}2.读取的文件内容信息写到指定的(.java)文件复制代码 代码如下:public static boolean writeFile(String cont, String path) {try {File dist new File(path);OutputStreamWriter writer new OutputStreamWriter(new FileOutputStream(dist),GBK);writer.write(cont);writer.flush();writer.close();return true;} catch (IOException e) {e.printStackTrace();return false;}}3.查找指定目录下所有符合条件的.java文件并更新文件信息复制代码 代码如下:/*** 查找文件* param f* throws IOException*/public static void findFile(File f) throws IOException {if(f.exists()) {if(f.isDirectory()) {for(File fs:f.listFiles(ff)) {findFile(fs);}} else {updateFile(f);}}}/*** 逐行读java文件* param f* throws IOException*/private static void updateFile(File f) throws IOException {String filePathStr f.getPath();System.out.println(开始读取文件的路径:::::::filePathStr);FileInputStream fis new FileInputStream(f);InputStreamReader isr new InputStreamReader(fis,Charset.forName(GBK)); //以gbk编码打开文本文件BufferedReader br new BufferedReader(isr, 8192 * 8);String line null;int linenum 0;StringBuffer res new StringBuffer();while((linebr.readLine())!null) {String updateStr updateStr(line);res.append(updateStr\r\n);if(!line.trim().equals(updateStr.trim())) {linenum ;}}br.close();//如果文件有修改则修改后的文件覆盖原有文件if(linenum0) {System.out.println();System.out.println(filePathStr:filePathStr);System.out.println(文件修改了linenum处。);System.out.println();String cont res.toString();ReadWriteFile.write(cont, filePathStr);}}/*** 验证读取的字符串信息* 和更新字符串信息* param str*/private static String updateStr(String str) {//判断字符串是否是需要更新的字符串boolean isok filterStr(str);int strNum StringValidation.strNum(str, StringValidation.ch);if(isok || strNum 0) {return str;} else {String temp ;for(int i1;istrNum/2;i) {temp //$NON-NLS-i$; //需要添加的字符}str strtemp;}return str;}//过滤文件类型private static FileFilter ff new FileFilter() {public boolean accept(File pathname) {String path pathname.getName().toLowerCase();logger.info(FileFilter path::::path);//只匹配 .java 结尾的文件if (pathname.isDirectory() || path.endsWith(.java)) {return true;}return false;}};/*** 过滤掉不需要处理的字符串* param str* return*/public static boolean filterStr(String str) {boolean isok false;//过滤字符串isok (str.indexOf(import )0)|| (str.indexOf(package )0)|| (str.indexOf( class )0)|| (str.indexOf(//$NON-NLS)0)|| (str.indexOf(//)0)|| (str.indexOf(/*)0)|| (str.indexOf(*)0)|| (str.trim().indexOf()0)|| (str.indexOf(\)-1)|| (.equals(str))|| isCh(str);return isok;}/*** 验证字符串是否含有中文字符* param str* return*/public static boolean isCh(String str) {Pattern pa Pattern.compile([\u4E00-\u9FA0]);Matcher m pa.matcher(str);boolean isok m.find();return isok;}总结当我们拿到一个别人给的需求先不要急于去处理先分析再分析然后做出最优的解决方案处理好这项工作。