这是我在这个IM gettng O / P的代码,evrythng如果罚款,但我无法打印输出到file.Canü帮助我在那里有错误实际上
| udayz999
import java.io.*;
import java.util.*;
public class MainClass {
public static void main(String[] args) throws Exception {
int flag=0,cindex=0;;
String fname=null,first=null,second=null;
TreeMap tm=new TreeMap();
File f=new File("D:\\final.txt");
f.createNewFile();
PrintWriter pw=new PrintWriter(new FileWriter(f));
File f1=new File("D:\\trnstons");
String line=null;
Map hm2;
Set s2;
String lkeys=null,lvalues=null;
int c=0;
//BufferedReader br1;
f1.mkdir();
String s[]=f1.list();
//System.out.println("TOTAL COUNT OF FILE::"+s.length);
int fcount=s.length;
for(String s1:s)
{
File f2=new File("D:\\trnstons\\"+s1);
BufferedReader br1=new BufferedReader(new FileReader(f2));
System.out.println( " "+f2.getName());
//pw.println("===========================FILE NAME IS::====================="+f2.getName());
line=br1.readLine();
while(line!=null)
{
while((line.equals("SUCCESS")))
{
line=br1.readLine();
while(line!=null)
{
//System.out.println(line);
cindex=line.indexOf(",");
if(cindex > (-1))
{
first=line.substring(0,cindex);
second=line.substring(cindex+1);
tm.put(second,first);
}
//pw.print(line);
line=br1.readLine();
}
////
flag=1;
break;
}
if(flag==1)
break;
line=br1.readLine();
}
/////
//System.out.println(tm);
}
//the values in tm are sorted according to values.Now for printing in file as k,v pairs we need to conver to LinkedHashMap
hm2=new LinkedHashMap(tm);
s2=hm2.entrySet();
Iterator i=s2.iterator();
//System.out.println("the values in the tm object are");
while(i.hasNext())
{
Map.Entry me=(Map.Entry)i.next();
lkeys= (String)me.getKey();/*as the getKey and GetValue returns key and value in the String form,convert in to ArrayList
(it implements RandonAccess(I),so its good at retriveing rather that any other List */
lvalues= (String)me.getValue();
System.out.print(lvalues);
System.out.print(",");
System.out.println(lkeys);
///trying to print in file
pw.print(lvalues);
pw.print(",");
pw.println(lkeys);
}
}
}