中文乱码问题

1,读取txt文件寸入sqlserver2000数据库
package timer;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

import db.DbConn;

public class Test {
public static DbConn DB = new DbConn();
public static void main(String[] args) throws Exception {
int num = 5;
int i = 0;
int b = 0;
int j = 0;
chinese ch = new chinese();
try {
String aa = "d:/c.txt";
String date = "";
int a;
Connection con = DB.getConnection();
File file = new File(aa);
InputStreamReader read = new InputStreamReader(new FileInputStream(file),"unicode");//这句是关键
BufferedReader br = new BufferedReader(read);
String sql = "insert into c(a) values(?)";
PreparedStatement pre = null;
pre = con.prepareStatement(sql);
List list = new ArrayList();
while(( date =br.readLine())!= null){
System.out.println(date);
list.add(date);
}
int total = list.size();
while (i < total) {
for (; i < list.size(); i++) {
String d = list.get(i).toString();
pre.setString(1, d);
pre.addBatch();
j++;
if (j % num == 0) {
pre.executeBatch();
pre.clearParameters();
pre.clearBatch();
b = total - j;
}
}
if (b < num) {
System.out.println(b);
pre.executeBatch();
}
}
pre.close();
System.out.println("over-----");
con.close();
br.close();
read.close();
} catch (FileNotFoundException e) {
System.out.println("找不到文件.....");
} catch (IOException ioe) {
System.out.println("IO异常.....");
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("不能插入......");
System.out.println(ex.getMessage());
System.out.println(ex.getStackTrace());
System.out.println(ex.getLocalizedMessage());
}

}
}
2.导出txt或者excle时候为文件起中文名称
String name = "地市信息发送数量统计";
String zi = "至";
String name1 = new String(name.getBytes("GBK"), "ISO8859_1");
String zi1 = new String(zi.getBytes("GBK"), "ISO8859_1");
将你要给文件起的名字进行这样的转换就可以了
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值