以下のコードは、単一のテキスト ファイル内の行またはフィールドを検索し、ファイルを 1 行ずつ読み取り、その行またはフィールドを " " またはその他の文字列に置き換えることができます。ここでは、pattern クラスと Matcher クラスを使用します。
これで質問が解決しない場合は、お知らせください。
java.io をインポートします。; java.util.regex をインポートします。; java.util.Properties をインポートします。パブリッククラスDeleteLine {
public static void main(String[] args) { BufferedReader br = null; { 文字列行 = null; を試してください。ファイル f = 新しいファイル("d:/xyz.txt");
String replaceString=properties.getProperty("replaceAll.String");
; br = new BufferedReader(new FileReader("d:/giri/scjp/");
while ( (line = br.readLine()) != null )//BufferedReader contains readline method
{
Pattern p=Pattern.compile(searchString);/*here u an specify the line u want to delete */
Matcher m=p.matcher(line);
line=m.replaceAll(replaceString);/*here replace String u can " " so that it will be emptied */
System.out.println(line);
}
//System.out.println(line);
}
}
} br = new BufferedReader(new FileReader("d:/xyz.txt")); 文字列行 = null;
}
catch (FileNotFoundException e)
{
System.out.println("File couldnt find");
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}