import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.LineNumberReader;
public class ReadingfromModellerOutput {
public static void main(String args[])throws Exception
{
// BufferedReader br = new BufferedReader(new FileReader("ModellerOutput.txt"));
LineNumberReader reader= new LineNumberReader(new FileReader("ModellerOutput1.txt"));
String line;
while ((line = reader.readLine()) != null)
{
if(line.startsWith("Summary"))
{
System.out.println(reader.getLineNumber());
for(int i=reader.getLineNumber();i<=(reader.getLineNumber()+50);i++)
{
System.out.println(reader.getLineNumber());
writeTofile(line);
}
}
}
}
public static void writeTofile(String line)
{
//System.out.println(reader.getLineNumber());
// for(int i=reader.getLineNumber();i<=(reader.getLineNumber()+50);i++)
// {
// System.out.println(reader.getLineNumber());
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Output_1.txt"), true));
System.out.println("Hi");
bw.write(line);
bw.newLine();
bw.close();
}
catch (Exception e) {}
}
}
我正在尝试编写一个代码来从一个文本文件中提取 50 行,该行以 “约束违规摘要”开头的行: 上面的代码正在编写同一行“约束违规摘要: 50 次”。请帮忙。