zoukankan      html  css  js  c++  java
  • RandomAccessFile 文件读写中文乱码解决方案!

    RandomAccessFile 读写文件时,不管文件中保存的数据编码格式是什么   使用 RandomAccessFile对象方法的 readLine() 都会将编码格式转换成 ISO-8859-1 所以 输出显示是还要在进行一次转码

    例子:

    package fileReadAndWrite;
    
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    
    
    /**
     * 测试文件读写
     * @author laobiao
     *
     */
    public class bigFileRW {
        
        public static void main(String[] args) throws Exception {
            RandomAccessFile ra = new RandomAccessFile("test.txt", "rw");
             ra.seek(0);
             ra.write("a bcd你好啊的撒法".getBytes());
             ra.seek(0);     
             System.out.println(new String(ra.readLine().getBytes("ISO-8859-1"),"utf-8"));//需要重新转码才能正常显示
             
             ra.close();
                
        }
    
         
        
    }
  • 相关阅读:
    数据库练习
    pymysql
    数据库索引
    数据库查询
    数据库操作
    数据库建表
    数据库初识
    shell 编程
    Struts2与SpringMVC
    SpringAOP
  • 原文地址:https://www.cnblogs.com/laobiao/p/5585862.html
Copyright © 2011-2022 走看看