目标二

import java.io.IOException;
public class Code {
	public static void main(String args[]) throws IOException{new  SystemIn();
	}
}
import java.io.*;
public class SystemIn {
	static InputStream in=System.in;      //键盘录入
	static StringBuilder sb=new StringBuilder();   //建立缓冲区	
	SystemIn() throws IOException{
		String file;
		String type;
		System.out.println("请输入文件目录");
		file=ReadIn();
		sb.delete(0,sb.length());	 
		System.out.println("请输入文件类型");	  
		type=ReadIn();

		Filecount count=new  Filecount(file,type);		  
	}
	public static String ReadIn() throws IOException{

		
		while(true){
			int ch=in.read();
			if(ch=='\r')
				continue;
			if(ch=='\n')
			{
				String name=sb.toString();				
				break;
			}
			else{
				sb.append((char)ch);
			}
		}

		return sb.toString();  
	}

}<pre name="code" class="java">import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class Filecount {
	    String file;
	    String type;
	    
	    int filenum;
	    
		Filecount(String file,String type) throws IOException{
			this.file=file;
			this.type=type;
			
			System.out.println(file);
			File dir = new File(file);
			
			List<File> list = new ArrayList<File>();
			count(dir,list);
	
		}
		
		public void count(File dir,List<File> list) throws IOException{                       // 计算目录下有类型文件个数
			File[] files = dir.listFiles();
			filenum=0;
			for(File file : files)
			{   
					if(file.getName().endsWith(type)){
							filenum++;
							System.out.println(file.getName());
							new SumCode(file);			
					}		
				}
			System.out.println(type+"类型文件个数:"+filenum);
			}
		}

 

import java.io.*;

/*
 * 8
 */
public class SumCode {
	
	 int BlankLine=0;
	 int CommentLine=0;
	 int CodeLine=0;
	 int SumLine=0;
	 
	 String regex="^[\\s&&[^\\n]]*$";

	       SumCode(File file) throws IOException {
		    	   boolean flag=false;
			       BufferedReader br;
	
		    	   br=new BufferedReader(new FileReader(file));          
		    	   //将文件读入缓冲区
		    	   String line=null;
		    	   
		    	   while((line=br.readLine())!=null){                             
		    		   //每一行进行读取
		    		   SumLine++;
		    			if (line.matches("^[\\s&&[^\\n]]*$")) { 
							BlankLine++; 
						} else if (line.startsWith("/*") && !line.endsWith("*/")) { 
							CommentLine++; 
							flag = true; 
						} else if (flag==true) { 
							CommentLine++; 
							if (line.endsWith("*/")) { 
								flag = false; 
							} 
						} else if (line.startsWith("//")) { 
								CommentLine++; 
						} else { 
							CodeLine++; 
						} 
		    	   }
			    	   
		       br.close();
		       
		       	System.out.println("空行数:"+BlankLine);
				System.out.println("注释行数:"+CommentLine);
				System.out.println("代码行数:"+CodeLine);
			    System.out.println("总行数:"+SumLine);
     
	}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值