Java追加文件内容并导出

来源:互联网 发布:adobe reader mac下载 编辑:程序博客网 时间:2024/06/05 00:59
 File tFile = new File("e:/writerOut");
try{

   String  tString = "汉字";    //声明String 变量;


    RandomAccessFile randomFile = new RandomAccessFile(tFile, "rw");  

      

        long fileLength = randomFile.length();    // 文件长度,字节数   

       

        randomFile.seek(fileLength);     // 将文件指针移到文件尾  


//randomFile.writerBytes(tString);  不建议用,会出现乱码问题


        randomFile.write(sb.toString().getBytes());  //写出,不会存在中文乱码问题


        randomFile.close();  //释放资源(应该放在finally里面)


    } catch (IOException e) {

    }