
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.TreeMap;
public class FileReadWrite{
/**
*@param args
*@throws IOException
*/
public static void write(StringBuffer bb,String string,
TreeMap FileWriter fw=new FileWriter(string,true); try{ br=new BufferedReader(new FileReader(string)); Set //fw.append("\\r\\n"); for(String ch:set){ fw.append(ch+ } br.close(); }catch(FileNotFoundException e){ e.printStackTrace(); } fw.close(); } public static TreeMap TreeMap try{ if(file.isFile()&&file.exists()){ InputStreamReader read=new InputStreamReader( new FileInputStream(file),encoding);BufferedReader bufferedReader=new BufferedReader(read); String lineTXT=null; while((lineTXT=bufferedReader.readLine())!=null){ bb=new StringBuffer(""); bb.append(lineTXT.toString().trim()); String res[]=bb.toString().split(""); if(res.length==8){ String date[]=res[1].split(""); if(date.length==6){ String LocationYearMonth=res[5]+"_"+date[5] +"_"+date[1]; if(!res[6].equals("null")){ LocationYearMonth=res[6]+"_"+date[5] +"_"+date[1]; System.out.println(lineTXT.toString().trim()); } if(map.get(LocationYearMonth)==null){ map.put(LocationYearMonth,1); }else{ Integer in=map.get(LocationYearMonth); map.put(LocationYearMonth,in.intValue()+1); } } } } read.close(); }else{ System.out.println("找不到指定的文件!"); } }catch(Exception e){ System.out.println("读取文件内容操作出错"); e.printStackTrace(); } return map; } }
