我想从文件读取并写入文件。输入文件如下读写文件 - Java空格
<ORLANDO> <0%>
As I remember, Adam, it was upon this fashion bequeathed me by will but poor a thousand crowns, and, as thou sayest,
<ORLANDO>
"A s I r e m e m b e r A d a m i t w a s u p o n t h i s f a s h i o n b e q u e a t h e d m e b y w i l l b u t p o o r a t h o u s a n d c r o w n s a n d a s t h o u s a y e s t c h a r g e d m y b r o t h e r o n ..."
我已经写了一个java程序来删除带标记的行,也用空格替换任何标点符号。但是每个写出来的字母之间都有一个空格,而且在两行之间还有很多空行。如何删除它们? 。请帮忙。
String line=null;
try {
BufferedReader br=new BufferedReader(new FileReader("filename"));
PrintWriter writer = new PrintWriter(new FileWriter("filename"));
try {
while((line=br.readLine())!=null)
{
if(!line.contains("<"))
{
line=(line.replaceAll("\\p{Punct}",""));
writer.println(line);
writer.flush();
}
}
}
运行代码,无法重复您的问题。输入文件的编码是什么? – jlordo
代码对我来说工作正常..我所做的只是删除了额外的'try'你有..检查编码问题。 – RadAl