HTML中字符大小写转换(java)

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader; 

/**
 * 将HTML中<  >中的字母大小写进行转换
 * 
@author 
 *
 
*/

public class ExchangeCase{
    
public static void main(String args[]) throws IOException{
        
        
boolean aFlg = false;//判斷"<>"用;
        int intCount = 0;//计算"<>"用;
        int intLine=0;//行数
        String strCurrentLine=null;//当前行
        String []dataSave = new String[10000];//将读到的每一行放进一个数组
        try {
            BufferedReader BRead 
= new BufferedReader(new InputStreamReader(
                    
new FileInputStream("C:/Html.html") ));//读取文件
         
            BufferedWriter BWriter
=new BufferedWriter(new FileWriter("C:/Html2.txt"));//转成后放到此文件
         
             
while((strCurrentLine=BRead.readLine())!=null){
                 dataSave[intLine]
=strCurrentLine;
                 intLine
=intLine+1;
             }

             
//System.out.println("総行数="+intLine);
             for(int i=0; i<intLine;i++){
                aFlg 
= false;
                intCount 
= 0;
                
for (int j = 0; j < dataSave[i].length(); j++{
                    
char cByte = dataSave[i].charAt(j);
                    
if (cByte == '<' && intCount == 0{
                        aFlg 
= true;
                    }

                    
if (cByte == '<'{
                        
++intCount;
                    }

                    
if (cByte == '>'{
                        
--intCount;
                    }

                    
if (cByte == '>' && intCount == 0{
                        aFlg 
= false;
                    }
 

                    
if (aFlg && intCount > 0{
                        
//转成小写  
                        if (cByte >= 'A' && cByte <= 'Z'{    //大写: cByte >= 'a' && cByte <= 'z'
                            cByte += 32;                            //大写: cByte -= 32;
                            
// System.out.print(cByte);
                            BWriter.write(cByte);
                            
continue;
                        }
 else {
                            
// System.out.print(cByte);
                            BWriter.write(cByte);
                            
continue;
                        }

                    }

                    
// System.out.print(cByte);
                    BWriter.write(cByte);
                }

                
// System.out.println();
                BWriter.newLine();
             }

             BRead.close();
             BWriter.close();
         
        }
 
        
catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }

 
}

posted @ 2008-04-02 11:09  kingkoo  阅读(3028)  评论(0编辑  收藏  举报