packagecom.dk.rf;import java.io.*;importjava.util.ArrayList;importjava.util.List;/*** Created by zzy on 17/1/9.*/
public classReadFile {public static voidmain(String[] args) {
String path= "/Users/zzy/Downloads/QQdownload/test-readhanzi.txt";
readFileByLines(path);
}/*** 以行为单位读取文件,常用于读面向行的格式化文件*/
public static voidreadFileByLines(String fileName) {
File file= newFile(fileName);
BufferedReader reader= null;try{
System.out.println("以行为单位读取文件内容,一次读一整行:");//reader = new BufferedReader(new FileReader(file));
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"GBK"));
String tempString= null;int line = 1;//一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
handleLines(tempString);char[] chars;
chars=tempString.toCharArray();
line++;if (line > 100){break;
}
}
reader.close();
}catch(IOException e) {
e.printStackTrace();
}finally{if (reader != null) {try{
reader.close();
}catch(IOException e1) {
}
}
}
}/*** 处理一行
*@paramline*/
public static voidhandleLines(String line){//System.out.println(line.length());//每一行数据分为96个字段
List strList= newArrayList();int start = 0;int end = 0;int [] ss = {42,42,42,8,3,1,1,1,1,1,6,10,11,11,11,11,11,21,21,21,4,6,12,4,6,4,3,2,12,6,8,15,40,3,4,6,10,1,1,5,2,2,2,2,4,4,11,11,12,12,12,12,3,3,8,1,8,8,8,8,8,8,8,8,8,8,8,1,16,8,8,8,8,8,8,32,2,1,2,14,4,3,9,12,3,1,8,1,12,15,21,1,2,1,1,97};for (int i = 0; i < ss.length; i++){if (i == 32){ //单独处理地址
char[] cc =line.toCharArray();int ss_32=0 ;// int ff = 0;
System.out.println("-------"+start);for (int j = start; j < start+ss[i]; j++) {
ss_32++;
ff++;if (!isLetter(cc[j])){//如果是汉字
ss_32++;
}if (ss_32 == 40){
ss[i]=ff;break;
}
}
}
end= start +ss[i];if(start>=line.length())return;
String temp=line.substring(start, end);
start=end;
strList.add(temp);
System.out.println("ss["+ i+ "]"+ss[i]+"temp="+temp);//TO ,设计业务,需要继续,春节后交接
}
}/*** 判断一个字符是Ascill字符还是其它字符(如汉,日,韩文字符)
*
*@paramc
*@return
*/
public static boolean isLetter(charc) {int k = 0x80;return (c / k) == 0 ? true : false;
}
}