-2

我的输入文件是......

Amrozi accused his brother, whom he called "the witness", of deliberately distorting his evidence.
agt(accuse(icl>do,equ>charge,cob>abstract_thing,agt>person,obj>person).@entry.@past,amrozi)
pos(brother(icl>male_sibling>thing,ant>sister),he(icl>person):01)
obj(accuse(icl>do,equ>charge,cob>abstract_thing,agt>person,obj>person).@entry.@past,brother(icl>male_sibling>thing,ant>sister))
obj(call(icl>do,com>communicate,plt>thing,plf>thing,agt>person,obj>volitional_thing).@present,brother(icl>male_sibling>thing,ant>sister))
agt(call(icl>do,com>communicate,plt>thing,plf>thing,agt>person,obj>volitional_thing).@present,he(icl>person):02)
nam(brother(icl>male_sibling>thing,ant>sister),witness(icl>perceiver>thing).@def.@double_quote)
man:01(distort(icl>falsify>do,agt>person,obj>thing).@entry,deliberately(icl>how,equ>intentionally,ant>accidentally,com>deliberate))
pos:01(evidence(icl>indication>thing),he(icl>person):03)
obj:01(distort(icl>falsify>do,agt>person,obj>thing).@entry,evidence(icl>indication>thing))
obj(brother(icl>male_sibling>thing,ant>sister),:01)
###
Referring to him as only "the witness", Amrozi accused his brother of deliberately distorting his evidence.
cob:01(refer(icl>consider>be,cob>uw,obj>thing).@entry,he(icl>person):01)
man:01(only(icl>how,equ>merely),as(icl>how,equ>equally,com>equal))
mod:01(witness(icl>perceiver>thing).@def.@double_quote,only(icl>how,equ>merely))
obj:01(refer(icl>consider>be,cob>uw,obj>thing).@entry,witness(icl>perceiver>thing).@def.@double_quote)
agt(accuse(icl>do,equ>charge,cob>abstract_thing,agt>person,obj>person).@entry.@past,amrozi)
pos(brother(icl>male_sibling>thing,ant>sister),he(icl>person):02)
obj(accuse(icl>do,equ>charge,cob>abstract_thing,agt>person,obj>person).@entry.@past,brother(icl>male_sibling>thing,ant>sister))
man:02(distort(icl>falsify>do,agt>person,obj>thing).@entry,deliberately(icl>how,equ>intentionally,ant>accidentally,com>deliberate))
pos:02(evidence(icl>indication>thing),he(icl>person):03)
obj:02(distort(icl>falsify>do,agt>person,obj>thing).@entry,evidence(icl>indication>thing))
man(accuse(icl>do,equ>charge,cob>abstract_thing,agt>person,obj>person).@entry.@past,:01)
obj(brother(icl>male_sibling>thing,ant>sister),:02)
###
Yucaipa owned Dominick's before selling the chain to Safeway in 1998 for $2.5 billion.
nam(yucaipa.@entry,dominick)
obj(own(icl>be,equ>posess,obj>thing,aoj>thing).@state,dominick)
tim(yucaipa.@entry,before(icl>how,tim<uw,obj>thing))
obj:01(sell(icl>exchange>do,cob>thing,agt>thing,obj>thing,ptn>thing).@entry,chain(icl>series>thing).@def)
ptn:01(sell(icl>exchange>do,cob>thing,agt>thing,obj>thing,ptn>thing).@entry,safeway)
tim:01(safeway,1998)
cob:01(sell(icl>exchange>do,cob>thing,agt>thing,obj>thing,ptn>thing).@entry,_)
mod:01(_,"2.5")
mod:01("2.5",billion(icl>quantity))
obj(before(icl>how,tim<uw,obj>thing),:01)
###

我需要读取文件的此内容并将其写入其他文件,方法是跳过第一行和 ### 之后的每一行到一个新文件中。我需要将内容与 ### 一起写入新文件中..only我需要删除###之后的行。我执行以下代码但它无法正常工作......

Scanner scanner1 = new Scanner(new File("E:out1.txt"));
scanner1.useDelimiter("###");
BufferedWriter fos1 = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("E:out2.txt")));
String line1="";
//while ((line1 = br.readLine()) != null)                       
while( scanner1.hasNextLine())//&&scanner1.hasNext()) {
    // scanner1.nextLine();
    if(scanner1.nextLine().equals("###")) {
        scanner1.nextLine();
    }
    fos1.append(scanner1.nextLine());
    fos1.newLine();

请帮忙...

4

1 回答 1

1

每次调用nextLine时,都会消耗一条线。

编辑后的答案,意识到您想要“###”行,而不是后面的行

试试这个作为你的while循环:

while(scanner1.hasNextLine())
{
    String line = scanner1.nextLine();
    fos1.append(line);
    fos1.newLine();
    if(line.equals("###"))
    {
         scanner1.nextLine();
    }
}

现在我们在测试是否是行时不使用“###”。

于 2013-10-31T18:15:18.047 回答