sample.txt的
FLTR TID:0000007899 RPC ID:0000137687队列:List Client-RPC:390620
USER:taranveer.vij@unisys.com Overlay-Group:1
我需要这样的东西
tempFile.log
FLTR TID:0000007899 RPC ID:0000137687队列:List Client-RPC:390620
USER:3 @#$ @ fghfkjCNBMFS!@fg Overlay-Group:1
我试过这个,但我无法做到这一点
private static void CreateTempFile() throws IOException
{
BufferedReader buff=new BufferedReader(new FileReader("D:\\AdhocTask_ClientLog005.log"));
PrintStream out=new PrintStream("D:\\tempFile.log");
String readline=null;
while((readline=buff.readLine())!=null)
{
if(readline.contains("FLTR"))
{
String how=(String) ((String) readline.subSequence(97,142)); //this gives taranveer.vij@in.unisys.com
String word=how.replace(how,"3@#$@fghfkjCNBMFS!@fg");
out.println(word);
}else{
out.println(readline);
}
}
out3.close();
buff.close();
}
但是在这个程序中只有“3 @#$ @ fghfkjCNBMFS!@fg”打印到整行。我想要完整的行,但只替换USER提交..这样的事情
FLTR TID:0000007899 RPC ID:0000137687队列:List Client-RPC:390620
USER:3 @#$ @ fghfkjCNBMFS!@fg Overlay-Group:1
答案 0 :(得分:0)
我认为整条线的问题在于:
String word=how.replace(how,"3@#$@fghfkjCNBMFS!@fg");
尝试改为:
String word=readline.replace(how,"3@#$@fghfkjCNBMFS!@fg");
希望这有帮助,