Java读取txt文件,计算2011年9月份的通话时间

 

public class test2 {  
      
/**  
* @param args  
* @throws IOException   
    */ 
    public static void main(String[] args) throws IOException {  
        // TODO Auto-generated method stub  
        File file = new File("C:\\Users\\Administrator\\Desktop\\a.txt");  
        FileInputStream inStream =new FileInputStream(file);  
        BufferedReader in = new BufferedReader(new FileReader(file));  
        int call=0,i=0;  
        String line=null;  
        while((line=in.readLine())!=null ){  
            //System.out.println(line);  
            int a=Integer.decode(line);  
            System.out.println(a+"秒");  
            call+=a;  
            i++;  
        }  
        while(inStream.read()!=-1){  
            //System.out.println(inStream.toString());  
            //call+=inStream.read();  
        }  
        int hour=call/3600;  
        int minute=(call%3600)/60;  
        int second=(call%60);  
        System.out.println(call+"秒");  
        System.out.println("共有"+i+"条记录,通话时间:"+hour+"小时"+minute+"分钟"+second+"秒");  
        System.out.print(hour*3600+minute*60+second+"秒");  
    }  
}  

 

本文出自 “阿凡达” 博客,请务必保留此出处http://shamrock.blog.51cto.com/2079212/702513

posted @ 2014-08-10 10:03  商商-77  阅读(189)  评论(0编辑  收藏  举报