文件处理续存操作
2017-12-27 16:44
211 查看
/** * 拷贝文件,文件存在可以从后面追加文件数据,可用于文件操作失败续存操作 * * @param fileDir * 被拷贝文件位置 * @param copyFileDir * 拷贝到的目标文件 * @param xuchuan * 文件存在是否从文件后面添加 * @throws IOException */ public static void copyFile(String fileDir, String copyFileDir, boolean xuchuan) throws IOException { // 原始文件 File fIn = new File(fileDir); RandomAccessFile in = new RandomAccessFile(fIn, "r");// 以只读写入方式打开 // 拷贝文件 File fOut = new File(copyFileDir); RandomAccessFile randomFile = new RandomAccessFile(fOut, "rw");// 以读写入方式打开 // 一次读多个字节 if (fOut.exists() && xuchuan) { long fileLong = 0; fileLong = fOut.length(); // 读取移动指针到指定位置 in.seek(fileLong); // 写入移动指针到指定位置 randomFile.seek(fileLong); } // 一次读多个字节 byte[] tempbytes = new byte[1024]; int byteread = 0; while ((byteread = in.read(tempbytes)) != -1) { // 写文件 randomFile.write(tempbytes, 0, byteread); } randomFile.close(); in.close(); }
相关文章推荐
- 郁金香论坛_Lua 标准库 文件读写操作及 输入输出处理
- 文件与目录操作命令;文本处理命令;信息显示命令
- 科学音频处理(一):怎样使用 Octave 对音频文件进行读写操作
- C++文件处理的几点操作
- 使用VBA操作文件(2):处理文件的VBA函数和语句
- 操作分布式文件之八:如何批量并行读写远程文件和事务补偿处理
- Spark处理日志文件常见操作
- 批处理文件(Batch File)里的Substring操作
- [译]File API之JavaScript文件操作(3)- 进度事件和错误处理
- 批处理操作压缩文件
- TX Text Control文字处理教程(2)- 文件操作
- window下批处理操作:从Linux机器下拷贝文件
- Java语言操作FTP服务进行文件的处理
- java 常见的文件字符处理操作 进程与线程
- C#文件操作、提取 、处理文件中数据
- awk 如何处理两个文件,实现类似数据库表连接的操作
- 通过bat文件 进行mysql 连接 或者 操作涉及 密码的,如果密码 中有 % 号的话要特殊处理
- DICOM医学图像处理:DICOM存储操作之“多幅BMP图像数据存入DCM文件”
- 一个批处理(BAT)文件中成功执行多个ant命令的操作
- C语言 文件操作7--文件错误处理