注释和取消注释 程序中的log日志
有点简单,但也是原创哦。。亲测有效,期待指正。
更改了log多行的问题。。
例如//Log
Util;
一、注释log
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
public class CommentLog {
public static String dirpath = "/home/google/com";
// public static String dirpath = "/home/java";
public static String filepath = "/home/java/test1";
public static String newStr = "LogUtil.";
public static String oldStr = "//LogUtil.";
public static boolean judge = false;
public static String str = null;
public static boolean MyPanduan(String str) {
String strTest = str.trim();
if(!strTest.endsWith(";")) {
judge = true;
} else {
judge = false;
}
return judge;
}
public static void writeStrtoFile(StringBuffer sb1, String path) {
try {
String sb = "" + sb1;
FileOutputStream fos = new FileOutputStream(path, false);// true原有续写,false是追加。如果源文件不存在就新建了
fos.write(sb.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void replaceDir(String Mdirpath) {
File file = new File(Mdirpath);
if (file.isDirectory()) {
File[] tempList = file.listFiles();
for (File fi : tempList) {
if (fi.isFile()) {
if (!fi.getAbsoluteFile().equals("LogUtil.java")) {
replaceFile(fi.getAbsolutePath());
}
judge = false;
} else {
replaceDir(fi.getAbsolutePath());
}
}
}
}
public static void replaceFile(String path) {
try {
// read file content from file
StringBuffer sb = new StringBuffer("");
FileReader reader = new FileReader(path);
BufferedReader br = new BufferedReader(reader);
while ((str = br.readLine()) != null) {
if (str.contains(newStr)) {
str = str.replaceAll(newStr, oldStr);
MyPanduan(str);
sb.append(str);
} else {
if (judge == true) {
str = "//".concat(str);
MyPanduan(str);
}
sb.append(str);
}
sb.append("\n");
}
br.close();
reader.close();
if (sb != null) {
writeStrtoFile(sb, path);
}
}
catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
replaceDir(dirpath);
}
}
二、取消注释
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CancelCommentLog {
public static String dirpath = "/home/google/com";
//public static String dirpath = "/home/java";
public static String filepath = "/home/java/test1";
public static String newStr = "LogUtil";
public static String oldStr = "//LogUtil";
public static boolean judge = false;
public static String str = null;
public static boolean MyPanduan(String str) {
str = str.trim();
if(!str.endsWith(";")){
judge = true;
} else {
judge = false;
}
return judge;
}
public static void writeStrtoFile(StringBuffer sb1, String path) {
try {
String sb = ""+sb1;
FileOutputStream fos = new FileOutputStream(path, false);// true原有续写,false是追加。如果源文件不存在就新建了
fos.write(sb.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void replaceDir(String Mdirpath){
File file = new File(Mdirpath);
if (file.isDirectory()) {
File[] tempList = file.listFiles();
for (File fi : tempList) {
if (fi.isFile()) {
replaceFile(fi.getAbsolutePath());
judge = false;
}
else{
replaceDir(fi.getAbsolutePath());
}
}
}
}
public static void replaceFile(String path){
try {
// read file content from file
StringBuffer sb= new StringBuffer("");
FileReader reader = new FileReader(path);
BufferedReader br = new BufferedReader(reader);
while((str = br.readLine()) != null) {
String regEx=" +//LogUtil";
String regEx1="//LogUtil";
Pattern pat=Pattern.compile(regEx);
Pattern pat1=Pattern.compile(regEx1);
Matcher mat=pat.matcher(str);
Matcher mat1=pat1.matcher(str);
if(mat.find()){
str=mat.replaceAll(newStr);
MyPanduan(str);
sb.append(str);
}
else if(mat1.find()){
str=mat1.replaceAll(newStr);
MyPanduan(str);
sb.append(str);
}else{
if(judge == true){
str =str.replaceAll("//", " ");
MyPanduan(str);
}
sb.append(str);
}
sb.append("\n");
}
br.close();
reader.close();
if(sb!=null){
writeStrtoFile(sb,path);
}
}
catch(FileNotFoundException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
replaceDir(dirpath);
}
}
注释和取消注释 程序中的log日志的更多相关文章
- 程序中编写log日志
public string logFile; ; private Stream s = null; StreamWriter sw = null; /// <summary> /// 用l ...
- Eclipse中各种文件的注释与取消注释的快捷键
Eclipse中各种文件的注释与取消注释的快捷键 Java文件: 注释和取消注释的快捷键都是:CTRL + / 或 Shift+Ctrl+C JS文件: 注释和取消注释的快捷键都是:CTRL + / ...
- IDEA XML注释与取消注释快捷键
IntelliJ IDEA和eclipse中编辑Java文件时,注释和取消注释的快捷键都是: "CTRL + / " 编辑xml文件时, 注释:CTRL + SHIFT + / 取 ...
- XML注释与取消注释快捷键
IntelliJ IDEA和eclipse中编辑Java文件时,注释和取消注释的快捷键都是: "CTRL + / " 编辑xml文件时, 注释:CTRL + SHIFT + / 取 ...
- matlab 大块注释和取消注释的快捷键
matlab 大块注释和取消注释的快捷键 注释:Ctrl+R 取消注释:Ctrl +T
- 在C#中winform程序中应用nlog日志工具
在C#中winform程序中应用nlog日志工具,配置文件简单应用. 文件名 nlog.config,请注意修改属性为"始终复制",发布时候容易遇到不存在文件的错误提示. 通过Nu ...
- 如何在xml文件中加注释或取消注释
1)加注释:Ctrl+Shift+/ 2)取消注释:Ctrl+Shift+\ 本文欢迎转载,但请注明作者与出处: 作者:Sophia 出处:http://www.cnblogs.com/Sophia- ...
- Visual Studio 注释与取消注释快捷键
注释: 先CTRL+K,然后CTRL+C 取消注释: 先CTRL+K,然后CTRL+U
- VS注释与取消注释快捷键
最近在使用VS2010开发ASP.Net,突然发现想全部注释时找不到注释的快捷键,网上查了下,原来很简单,只是需要使用组合键. 注释: 先CTRL+K,然后CTRL+C 取消注释: 先C ...
随机推荐
- CC2530低功耗设置(针对终端设备)
一. 终端设备只完成发送数据 1.开启POWER_SAVING 预编译 2.f8wConfig_cfg 中的RFD_RCVC_ALWAYS_ON=FALSE 3.f8wConfig_cfg中四个DPo ...
- ASP.NET 实现伪静态网页方法
方法一:利用Httphandler实现URL重写(伪URL及伪静态) 我们有时候会见到这样的地址:“http://www.huoho.com/show-12-34.html”,你或许认为在站点服务器根 ...
- java 中的好东西 jackson
转自: https://github.com/FasterXML/jackson 重要的是: jackson 支持 第三方数据类型 jsonobject jsonarray( json.org/jav ...
- 2013-7-28 802.11n帧聚合
芯片开发阶段的帧聚合迥异于商用AP,前者更偏向实现过程,后者偏向结果.也就是说用户在使用商用设备时不会管你特性是如何实现的,他们只关心效果,开启这个功能能否实实在在的提高AP的吞吐量. 网上搜索了众多 ...
- 【Tomcat-原】如何在Myeclipse中添加本地的Tomcat
2014-10-27 16-24-09 liulin 说明: Myeclipse中自带Tomcat,如果不想用Myeclipse自带的Tomcat,可以使用本地的Tomcat, 下面将介绍如何在My ...
- 【精】Linux磁盘I/O性能监控之iostat详解
[精]Linux磁盘I/O性能监控之iostat详解 Linux命令详解----iostat 使用iostat分析IO性能
- 在Linux 系统 Latex安装 使用入门教程
来源: http://blog.chinaunix.net/u/25605/showart_2100398.html 入门介绍好文:TeX.LaTeX.TeXLive 小结 笔记详情:http://v ...
- 微信公众平台测试帐号的注册与使用(自己的服务器<---->微信后台<---->测式公众号)
打开注册的网址:http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login 用手机微信扫描网页左边的二维码,然后在手机上确认即可: 至此 ...
- osx 安装redis
brew install redis 想关文章 http://www.tuicool.com/articles/nM73Enr http://www.iteye.com/topic/1124400
- 深度学习RNN实现股票预测实战(附数据、代码)
背景知识 最近再看一些量化交易相关的材料,偶然在网上看到了一个关于用RNN实现股票预测的文章,出于好奇心把文章中介绍的代码在本地跑了一遍,发现可以work.于是就花了两个晚上的时间学习了下代码,顺便把 ...