java string中文_java处理含有中文的字符串.

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;

}

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值