⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 analy3.java

📁 编写一个文本文件分析程序
💻 JAVA
字号:
import java.io.*;
import java.lang.*;

public class analy3

{
  public static void main(String args[])throws IOException	
  
  {     
        
  		BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
		System.out.println("input you want to origin_file name:");
		String str1=s.readLine();
		System.out.println("input you want to analyfile_name:");
		String str2=s.readLine();
		copy1 x=new copy1(str1,str2);
        x.Analysis(str1,str2);
        
   }     
        
}  
 
  class FileException extends IOException
  {  
    String str;
    public FileException(String str1)
      {
        str=str1;	
      }      
     public void FileException1()
      {
       	System.out.println(str);
      }	
    
  }
  
  
  
  
  
  class copy1
  {
  	String origin_name;
   	StreamTokenizer types;
   	StreamTokenizer types1;
   	String des_name; 
      	  	
  	public copy1(String a,String b)
  	{
  	  origin_name=a;
  	  des_name=b;
  	
  	}
  	
  	public void Analysis(String origin_name,String des_name)
     {
            int i,j,k,line;
		    int line1=0;
		    boolean check=false;
		    boolean check2;
		    
		    String temp;
		    String bijiao;
		    
		    i=0;j=1;k=0;
       try
       { 
        
		 File originfile=new File(origin_name);
		 FileReader origin=new FileReader(originfile);
		 BufferedReader from=new BufferedReader(origin);  	
		 
		 File desfile=new File(des_name);
		 FileReader des=new FileReader(desfile);
		 BufferedReader to=new BufferedReader(des); 
		 String br=to.readLine();
		 FileWriter fw=new FileWriter("d:\\result.txt",true);
		 fw.write("被拼写检查的文件名:"+origin_name+"+"+"  词典名:"+br);
		 fw.write("\r");
		 fw.write("\n");
		 fw.close();
		 
		 if(!originfile.exists()) throw new FileException("there is not exist this file");
		 else  if(!originfile.isFile())throw new FileException("this is not file");
		       else if(!originfile.canRead()) throw new FileException("the file is not read");
		           else   
		   	        {
		   	   		 types=new StreamTokenizer(from);
		   	   		 types1=new StreamTokenizer(to);
		   	   		 
		   	   		 
	                 types.ordinaryChar(' ');
	                 types1.ordinaryChar(' ');
	                 types1.ordinaryChar(',');
	                
		             try
		    	    {
		    	      while(types.nextToken()!=StreamTokenizer.TT_EOF)
	            	   {
	            	   	 
	            	   	 types.eolIsSignificant(true);
			             switch(types.ttype)
				        {
			             case StreamTokenizer.TT_EOL: {System.out.println("^^^^^^^^^^^^^^^wu"); k++;j=0; break;}
			             case StreamTokenizer.TT_NUMBER: break;						 
				         case StreamTokenizer.TT_WORD:
				            {
				              bijiao=types.sval; 
				              System.out.println();
				              System.out.print(" "+bijiao+" ");
				     	      check2=true;
				     	      
				              while((types1.nextToken()!=StreamTokenizer.TT_EOF)&&check2)
					            {
					              switch(types1.ttype)
						          {
						          case StreamTokenizer.TT_EOL:line1++;break;
						          case StreamTokenizer.TT_WORD:
						          
						             temp=types1.sval;
						             i=temp.compareTo(bijiao);
						             if(i==0)
					     	         {
						      	       System.out.print("the word is true");						              	                   
						               check2=false;
						               check=false;
						                break;
						              }
						              
						             else             	              
						              {
						               System.out.print("*");
						               check=true;
						               break;
						              }
						           default:break;             
						           }
						        } 
						        
				            if(check)
				            {
				              System.out.println("the wrong word at: "+k+" line.the "+j+" ge!")	;
				              System.out.println("the word is: "+types.sval+" wrong!");
				              
				              fw=new FileWriter("d:\\result.txt",true);
				              fw.write("出错单词:");
				              
				              fw.write(types.sval);
				              fw.write("  ");				              				              
				              fw.write("位于第"+k+"行");
				              fw.write("\r");
				              fw.write("\n");
				              fw.close();
				              
				            }
				             j++;line1=0;
				             to.close();
				             
				             desfile=new File(des_name);
		                     des=new FileReader(desfile);
				             to=new BufferedReader(des);
				             types1=new StreamTokenizer(to);
				             
				             break;
				   	      }
				   	      
				     case 32: break;
				     default: break;
				      }
		            }
		         }
			   //show("the number is",i);
			   //show("the word is",j);
			   //show("the char is",k);
			 
			    catch(IOException e)  
			    {
			      System.out.println("anoymaly information:"+e.getClass());
			      e.printStackTrace();
			    }
			   
		     }//else	
  			
	     }
	        
	       
	   
	    catch(FileException e)
            {
         	  e.FileException1();
         	  
         	}
        catch(IOException e) 	
            {
        	  System.out.println("anoymaly information:"+e.getClass());
        	  
            }
	
		
	 }
	
	
  			
      public void show(String str1,int d)			

            {
              System.out.println(str1+":"+d);
            }
            

 }
			


   	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -