java-映射内存
发布日期:2021-10-19 19:33:10
浏览次数:2
分类:技术文章
本文共 1122 字,大约阅读时间需要 3 分钟。
package UDPDemo;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.RandomAccessFile;import java.nio.ByteBuffer;import java.nio.MappedByteBuffer;import java.nio.channels.FileChannel;public class RAMMapped { /** * @param args */ public static void main(String[] args) throws IOException{ File infile2 = new File ("F:"+File.separator+"maoxiao.txt"); RandomAccessFile infile = new RandomAccessFile(infile2,"rw"); File outfile = new File("F:"+File.separator+"out.txt"); FileOutputStream fot = new FileOutputStream(outfile); FileChannel ichannel = infile.getChannel(); FileChannel ochannel = fot.getChannel(); MappedByteBuffer inbuf = ichannel.map(FileChannel.MapMode.READ_WRITE, 0, infile.length());//将文件映射到内存 ByteBuffer outbuf = ByteBuffer.allocate((int) infile.length()); ichannel.read(inbuf); inbuf.flip(); while(inbuf.hasRemaining()){ outbuf.put(inbuf.get()); } outbuf.flip(); ochannel.write(outbuf); inbuf.clear(); outbuf.clear(); fot.flush(); ochannel.close(); fot.close(); ichannel.close(); }}
转载地址:https://blog.csdn.net/u013494310/article/details/19507973 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
感谢大佬
[***.8.128.20]2024年04月16日 21时50分05秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
python - 【用户、商品】【购买、浏览】数据处理
2019-04-27
python - sql + pandas 与 sqlite 结合
2019-04-27
python - 使用sql 分析(06 - 15)国内各省GDP
2021-06-30
python - 抓取汇率数据分析美元和欧元对RMB的变化曲线
2021-06-30
python 数据科学 - 【回归分析】 ☞ 线性回归(1)
2021-06-30
python 数据科学 - 【回归分析】 ☞ 线性回归(2)
2021-06-30
python - 批量更改文件名(过滤掉某个字符串)
2021-06-30
python 数据科学 - 【分类模型】 ☞ 决策树
2021-06-30
python - zip、numpy.c 函数
2021-06-30
python 数据科学 - 【分类模型】 ☞ 逻辑回归
2021-06-30
python 数据科学 - 【分类模型】 ☞ 稳健滴 SVM 支持向量机
2021-06-30
python - selenium 处理 alert
2021-06-30
Java - Set、List、Map
2021-06-30
Java - OnlyLady Spider(HttpClient 4.5 )
2021-06-30
Math - 高斯分布(正态分布)
2021-06-30
android学习笔记----简易音乐播放器原理
2021-06-30
2. Add Two Numbers(链表尾插法)
2021-06-30