package com.dell.tool;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.util.Calendar;public class OmuTool {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
readFile();
} private static void readFile() {
try {
File fin = new File("D:\\Program Files\\OMU_Tool\\result.txt");
BufferedReader br = new BufferedReader(new FileReader(fin));
File fout = new File("D:\\spit_result.txt");
if (fout.exists())
fout.delete();
else
fout.createNewFile();
FileWriter fw = new FileWriter(fout);
BufferedWriter bw = new BufferedWriter(fw);
String str = null;
do {
str=br.readLine();
str=deleteComments(str);
if(str.length()==0)continue;
bw.write(str);
bw.newLine();
System.out.println(str.trim());
} while (str != null);
bw.flush();
br.close();
bw.close();
} catch (Exception e) {
System.err.println("File not found!");
}
} static String deleteComments(String str) {
if (str == null)
return str;
int zos = str.indexOf("框");
if (zos < 0)
return str;
return str.substring(0, zos - 3);
}
}
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.util.Calendar;public class OmuTool {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
readFile();
} private static void readFile() {
try {
File fin = new File("D:\\Program Files\\OMU_Tool\\result.txt");
BufferedReader br = new BufferedReader(new FileReader(fin));
File fout = new File("D:\\spit_result.txt");
if (fout.exists())
fout.delete();
else
fout.createNewFile();
FileWriter fw = new FileWriter(fout);
BufferedWriter bw = new BufferedWriter(fw);
String str = null;
do {
str=br.readLine();
str=deleteComments(str);
if(str.length()==0)continue;
bw.write(str);
bw.newLine();
System.out.println(str.trim());
} while (str != null);
bw.flush();
br.close();
bw.close();
} catch (Exception e) {
System.err.println("File not found!");
}
} static String deleteComments(String str) {
if (str == null)
return str;
int zos = str.indexOf("框");
if (zos < 0)
return str;
return str.substring(0, zos - 3);
}
}
IP: 16.165.15.131
产品类型: aBSC
语言类型: Chinese
工作区 = sion_a
主用工作区版本 = B900R414C00A010
备用工作区版本 = B900R914C00A909
0 框 aaaaaaaaaaaaaaaaa
0 框 aaaaaaaaaaaaa
0 框 aaaaaaaaaaaaaaaa
查询OK
==================================================
IP: 16.165.15.131
产品类型: aBSC
语言类型: Chinese
工作区 = sion_a
主用工作区版本 = B900R414C00A010
备用工作区版本 = B900R914C00A909
0 框 aaaaaaaaaaaaaaaaa
0 框 aaaaaaaaaaaaa
0 框 aaaaaaaaaaaaaaaa
查询OK
while ((str = br.readLine()) != null) {
str = deleteComments(str);
if (str.length() == 0)
continue;
bw.write(str);
bw.newLine();
System.out.println(str.trim());
} ;
if (str.length() == 0)
改成:
if (str == null || str.length() == 0)2 不要catch异常后打一个不能反映原来面貌的log
catch (Exception e)
{
e.printStackTrace();
}另外,楼主看起来在做日志分析,linux下可以用grep就可以了grep -V "框" result.txt > split_result.txt
package com.dell.tool;import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import java.util.Calendar;public class OmuTool{
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
readFile();
}private static void readFile() {
try {
File fin = new File("D:\\result.txt");
BufferedReader br = new BufferedReader(new FileReader(fin));
File fout = new File("D:\\spit_result.txt");
if (fout.exists())
fout.delete();
else
fout.createNewFile();
FileWriter fw = new FileWriter(fout);
BufferedWriter bw = new BufferedWriter(fw);
String str = null;
do {
str=br.readLine();
str=deleteComments(str);
if(str.length()==0)continue;
bw.write(str);
bw.newLine();
System.out.println(str.trim());
} while (str != null);
bw.flush();
br.close();
bw.close();
} catch (NullPointerException e) { //空指针异常,调用str.length()引起的,楼上们正解,我也学习一下
System.err.println("空指针异常!");
}
catch (Exception e) {
System.err.println("File not found!");
}
}static String deleteComments(String str) {
if (str == null)
return str;
int zos = str.indexOf("框");
if (zos < 0)
return str;
return str.substring(0, zos - 3);
}
}