我需要根据条件将文件中的一行复制到另一个文件这是我的代码
import org.apache.commons.io.FileUtils;
public class FileCopy {
public static void main(String args[]) throws IOException {
File source = \\
File fileToCopyFrom \\
File target :\\
if (!target.exists()) {
target.createNewFile();
}
PrintStream fstream =new PrintStream(target);
BufferedReader brSource = new BufferedReader(new FileReader(source));
BufferedReader brFileToCopyFrom = new BufferedReader(new FileReader(fileToCopyFrom));
String lineSource;
String lineToCopy;
while((lineSource = brSource.readLine()) != null) {
while ((lineToCopy=brFileToCopyFrom.readLine())!=null) {
if (lineToCopy.contains(lineSource.substring(lineSource.indexOf("_")+1, lineSource.indexOf(".")-1)))
fstream.println(lineToCopy);
}
}
}}
但它只复制第一行错误在哪里?