- 青岛雅思—专家谈雅思考试发展趋势
- 河南2011上半年自考网上报名入口 点击进入
- 2011年广东省护士资格考试报名现场确认时间
- 2011上半年乐山五通桥区会计从业考试报名3月10日-4月1
- 哈尔滨香坊区2011护士资格考试报名现场确认时间
- 2011什邡第一次会计从业资格考试报名3月1日-4月15日
- 2011什邡第二次会计从业资格考试报名7月1日-9月16日
- 2011年中山市护士资格考试报名工作的通知
- 长安大学2011考研成绩查询入口 点击进入
- 西华大学2011考研成绩查询入口 点击进入
- 中国地质大学(武汉)2011考研成绩3月3日查询
- 中南民族大学2011考研成绩查询3月4日开始
- 沈阳建筑大学2011考研成绩查询入口 点击进入
- 沈阳工业大学2011考研成绩查询入口 点击进入
java读取utf8类型的文件
来源:求学问校网 发表时间:2012-07-13 浏览 164 次
源文件为utf-8格式,且里面包含中文,如:
in (飝',飱',餌',餕') then '电信'
in (飚',飛',飜',飩',飳',飴',餏',餑',餒') then '联通'
1,不加转码的时候中文会乱码:
Java代码
1.public static void main(String[] args) throws Exception {
2. File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
3. InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
4. BufferedReader bufReader = new BufferedReader(insReader);
5. String line = new String();
6. while ((line = bufReader.readLine()) != null) {
7. System.out.println(line);
8. }
9. bufReader.close();
10.}
public static void main(String[] args) throws Exception {
File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
BufferedReader bufReader = new BufferedReader(insReader);
String line = new String();
while ((line = bufReader.readLine()) != null) {
System.out.println(line);
}
bufReader.close();
}
Java代码
1.in (飝',飱',餌',餕') then '鐢典俊'
2.in (飚',飛',飜',飩',飳',飴',餏',餑',餒') then '鑱旈?'
in (飝',飱',餌',餕') then '鐢典俊'
in (飚',飛',飜',飩',飳',飴',餏',餑',餒') then '鑱旈?'
2,如果对string进行utf-8编码,某些中文加单引号会导致乱码:
Java代码
1.public static void main(String[] args) throws Exception {
2. //String charsetName = "UTF-8";
3. File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
4. InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
5. BufferedReader bufReader = new BufferedReader(insReader);
6. String line = new String();
7. while ((line = bufReader.readLine()) != null) {
8. System.out.println(new String(line.getBytes(),"utf-8"));
9. }
10. bufReader.close();
11. }
public static void main(String[] args) throws Exception {
//String charsetName = "UTF-8";
File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
BufferedReader bufReader = new BufferedReader(insReader);
String line = new String();
while ((line = bufReader.readLine()) != null) {
System.out.println(new String(line.getBytes(),"utf-8"));
}
bufReader.close();
}
in (飝',飱',餌',餕') then '电信'
in (飚',飛',飜',飩',飳',飴',餏',餑',餒') then '联通'
1,不加转码的时候中文会乱码:
Java代码
1.public static void main(String[] args) throws Exception {
2. File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
3. InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
4. BufferedReader bufReader = new BufferedReader(insReader);
5. String line = new String();
6. while ((line = bufReader.readLine()) != null) {
7. System.out.println(line);
8. }
9. bufReader.close();
10.}
public static void main(String[] args) throws Exception {
File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
BufferedReader bufReader = new BufferedReader(insReader);
String line = new String();
while ((line = bufReader.readLine()) != null) {
System.out.println(line);
}
bufReader.close();
}
Java代码
1.in (飝',飱',餌',餕') then '鐢典俊'
2.in (飚',飛',飜',飩',飳',飴',餏',餑',餒') then '鑱旈?'
in (飝',飱',餌',餕') then '鐢典俊'
in (飚',飛',飜',飩',飳',飴',餏',餑',餒') then '鑱旈?'
2,如果对string进行utf-8编码,某些中文加单引号会导致乱码:
Java代码
1.public static void main(String[] args) throws Exception {
2. //String charsetName = "UTF-8";
3. File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
4. InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
5. BufferedReader bufReader = new BufferedReader(insReader);
6. String line = new String();
7. while ((line = bufReader.readLine()) != null) {
8. System.out.println(new String(line.getBytes(),"utf-8"));
9. }
10. bufReader.close();
11. }
public static void main(String[] args) throws Exception {
//String charsetName = "UTF-8";
File f = new File("D:/youni_insert_youni_file_transfer_ft.pl");
InputStreamReader insReader = new InputStreamReader(new FileInputStream(f));
BufferedReader bufReader = new BufferedReader(insReader);
String line = new String();
while ((line = bufReader.readLine()) != null) {
System.out.println(new String(line.getBytes(),"utf-8"));
}
bufReader.close();
}