程序逐行读取文件。
如果程序在一行中找到[@: Object successfully summoned]
,它不会写入第二个文件。
问题可能出在 try/catch/finally 部分。我已经尝试了很多次更改,但我无法解决问题。
这是我编程的:
package stringsHerkennen;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class MC {
private static PrintWriter outputFile;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException{
FileInputStream fstream = null;
FileWriter fwriter = null;
fstream = new FileInputStream("C:\\Users\\Tim\\Documents\\test.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
fwriter = new FileWriter("bewerkte log.txt", true);
outputFile = new PrintWriter(fwriter);
try{
while ((strLine = br.readLine()) !=null) {
try{
System.out.println(strLine);
String b = strLine;
String tokens[] = strLine.split("]: ");
String c = tokens[1].toString();
//System.out.println(tokens[1]);
Hamming H = new Hamming("[@: Object successfully summoned]", c);
int Pi = H.getHammingDistance();
//System.out.println(Pi);
if(!(Pi==0)){
//System.out.println("geschreven naar file");
outputFile.println(b);
//System.out.println("schrijven naar andere file");
}
else{
//System.out.println("niet geschreven naar file");
}
//try2
}
catch(Exception ArrayIndexOutOfBoundsException){
//System.out.println("Schrijven naar File");
outputFile.println(strLine);
}
finally {
if (fstream != null)
fstream.close();}
}
//try1
}
catch(Exception ArrayIndexOutOfBoundsException){
fstream.close();
br.close();
}
finally {
if (fstream != null)
fstream.close();}
System.out.println("klaar");
}
}
这是您要过滤的文本文件
sun.nio.cs.StreamDecoder.readBytes(Unknown Source) ~[?:1.7.0_13]#- at
sun.nio.cs.StreamDecoder.implRead(Unknown Source) ~[?:1.7.0_13]
at sun.nio.cs.StreamDecoder.read(Unknown Source) ~[?:1.7.0_13]
at java.io.InputStreamReader.read(Unknown Source) ~[?:1.7.0_13]
at java.io.BufferedReader.fill(Unknown Source) ~[?:1.7.0_13]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.7.0_13]
at java.io.BufferedReader.readLine(Unknown Source) ~[?:1.7.0_13]
at ll.run(SourceFile:78) [minecraft_server.1.7.2.exe:?]
[15:39:13] [Server thread/INFO]: Starting minecraft server version 1.7.2
[15:39:13] [Server thread/INFO]: Loading properties
[15:39:13] [Server thread/INFO]: Default game type: SURVIVAL
[15:39:13] [Server thread/INFO]: Generating keypair
[15:39:13] [Server thread/INFO]: Starting Minecraft server on *:25565
[15:39:13] [Server thread/INFO]: Preparing level "world 3"
[15:39:13] [Server thread/INFO]: Preparing start region for level 0
[15:39:14] [Server thread/INFO]: Done (0,820s)! For help, type "help" or "?"
[17:09:01] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:01] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:01] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:01] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:02] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:02] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:02] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:02] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:02] [Server thread/INFO]: [@: Object successfully summoned]
[17:09:02] [Server thread/INFO]: [@: Object successfully summoned]