我有一个包含此数据的文本文件。
<Equity Chart>
2004-01-21 00:00,100000.00
2004-02-21 00:00,-9950.00
2004-03-20 00:00,-4250.00
<Summary Table>
Net Profit=-$101,100.00
Total Trades=2
Wins=0
Losses=2
Aborted Entries=0
Fatal Errors=0
Win Rate=0.00%
Max Draw Down=-$104,250.00
Gross Profit=$0.00
Gross Loss=-$101,100.00
Profit Factor=0.0
Max Consecutive Wins=0
Max Consecutive Losses=2
Peak Risk=$inf
Average Risk=$inf
Return On Avg. Risk=0.00%
Average Win Size=N/A
Average Loss Size=-$50,550.00
Avg. Win: Avg. Loss=N/A
Largest Win=N/A
Largest Loss=-$93,650.00
Max DIT=2
Min DIT=2
Average DIT=2.0
<Table Of Trades>
"Expiration","Entry Date","Exit Date","DIT","PnL","Peak Risk","Return on Risk","Opening Balance","Closing Balance","Starting IV","Ending IV","IV Change","IV Change Pct.","Starting UL Price","Ending UL Price","Price Movement","Price Movement STDEV","Adjustments"
"21-Feb-04","02-Feb-04","03-Feb-04","2","-$93,650.00","$inf","-0.00%","$100,000.00","-$9,950.00","0.14","0.15","0.0","1.64%","$1,135.26","$1,136.79","$1.53","0.13","13"
"20-Mar-04","01-Mar-04","02-Mar-04","2","-$7,450.00","$inf","-0.00%","$6,350.00","-$4,250.00","0.12","0.12","-0.0","-3.19%","$1,155.97","$1,156.26","$0.29","0.03","2"
我希望每个组分别打印出来,
System.out.print(<Equity Chart>);
output: 2004-01-21 00:00,100000.00
2004-02-21 00:00,-9950.00
2004-03-20 00:00,-4250.00
与(汇总表)和(交易表)相同。我怎么做到这一点?
这是我创建的代码。
File newFile = new File(outputFolder + File.separator + fileName+".txt");
Scanner scan = new Scanner(newFile);
while (scan.hasNextLine()) {
String line = scan.nextLine();
System.out.println(line);
}
答案 0 :(得分:0)
你可以从中得到一些想法
Scanner scanner=new Scanner(new File("/home/ruchira/Text.txt"));
StringBuilder sb1=new StringBuilder();
StringBuilder sb2=new StringBuilder();
StringBuilder sb3=new StringBuilder();
String line1=new String();
String line2=new String();
while (scanner.hasNextLine()) {
if(scanner.nextLine().equals("<Equity Chart>")){
while(!(line1=scanner.nextLine()).equals("<Summary Table>")){
sb1.append(line1+"\n");
}
} else if(line1.equals("<Summary Table>")){
while(!(line2=scanner.nextLine()).equals("<Table Of Trades>")){
sb2.append(line2+"\n");
}
line1="";
}else if(line2.equals("<Table Of Trades>")){
while (scanner.hasNextLine()){
sb3.append(scanner.nextLine()+"\n") ;
}
}
}
System.out.println("<Equity Chart>\n"+sb1.toString().trim());
System.out.println("=====================================");
System.out.println("<Summary Table>\n"+sb2.toString().trim());
System.out.println("=====================================");
System.out.println("<Table Of Trades>\n"+sb3.toString().trim());