-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)
###

ファイルのこのコンテンツを読み取り、最初の行と ### の後の各行を新しいファイルにスキップして、他のファイルに書き込む必要があります。新しいファイルに ### とともにコンテンツを書き込む必要があります..のみ### の後の行を削除する必要があります。次のコードを実行しますが、正しく機能しません...

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たびに、1 行消費します。

編集された回答、「###」行が必要であることに気付きましたが、その後の行は必要ありません

これをwhileループとして試してください:

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

これで、それが行であるかどうかをテストするときに、「###」を消費しなくなりました。

于 2013-10-31T18:15:18.047 に答える