在读取双字节字符时,主要涉及到编码的选取:
Java代码 
 ![]()
class="star" src="/Upload/Images/2014111413/40B102E0EF997EA6.png" alt="收藏代码" />
- public static boolean isRightfulTXT(File f) {  
-   
-   String regexp="[^\\x00-\\xff]";
-   Pattern p=Pattern.compile(regexp);  
-     
-   try {  
-    FileInputStream fis=new FileInputStream(f);  
-    
-    InputStreamReader isr=new InputStreamReader(fis, "GBK");  
-    BufferedReader br=new BufferedReader(isr);  
-    String line="";  
-    while((line=br.readLine())!=null){  
-     
-     
-     Matcher m=p.matcher(line);  
-     if(m.find()){  
-      fis.close();  
-      isr.close();  
-      br.close();  
-      return false;  
-     }    
-    }    
-    fis.close();  
-    isr.close();  
-    br.close();  
-   } catch (FileNotFoundException e) {  
-    
-      
-    e.printStackTrace();  
-   } catch (UnsupportedEncodingException e) {  
-    
-    e.printStackTrace();  
-   } catch (IOException e) {  
-    
-    e.printStackTrace();  
-   }  
-    
-   return true;    
-  }  
 以上代码功能:检测txt文件中是否含有双字节字符,若有返回假,否则返回真。