当前位置: 首页 > 工具软件 > Mark > 使用案例 >

mark一个

柴深
2023-12-01



今天在写一个reader和writer程序,结果出现下面的问题,

String temp = read.readLine();
while(temp != null){
temp = temp.replaceAll("\\[Loaded ", "");//去除开头[Loaded 
temp = temp.replaceAll("\\.", "/");//将‘.’换成‘/’
temp = temp.replaceAll(" from.*", "\r\n");//去除结尾多余的frome部分
write.write(temp);//写入文件,
//write.newLine();//换行
temp = read.readLine();
}


原文件:

[Loaded java.lang.Object from shared objects file]
[Loaded java.io.Serializable from shared objects file]
[Loaded java.lang.Comparable from shared objects file]
[Loaded java.lang.CharSequence from shared objects file]
[Loaded java.lang.String from shared objects file]
[Loaded java.lang.reflect.GenericDeclaration from shared objects file]
[Loaded java.lang.reflect.Type from shared objects file]
[Loaded java.lang.reflect.AnnotatedElement from shared objects file]
[Loaded java.lang.Class from shared objects file]

能够成功实现一行一行的数据:

java/lang/Object
java/io/Serializable
java/lang/Comparable
java/lang/CharSequence
java/lang/String
java/lang/reflect/GenericDeclaration
java/lang/reflect/Type
java/lang/reflect/AnnotatedElement

如果改一下:

String temp = read.readLine();
while(temp != null){
temp = temp.replaceAll("\\[Loaded ", "");//去除开头[Loaded 
temp = temp.replaceAll("\\.", "/");//将‘.’换成‘/’
temp = temp.replaceAll(" from.*", "");//去除结尾多余的frome部分
write.write(temp);//写入文件,
write.newLine();//换行

temp = read.readLine();
}

会有多余的空行出现:

java/lang/Object


java/io/Serializable


java/lang/Comparable


java/lang/CharSequence


java/lang/String

 类似资料: