From c87236047c0362f91cf4fdbf754276cb9cfab165 Mon Sep 17 00:00:00 2001 From: hequan_waynaqua <1669738430@qq.com> Date: Tue, 11 Aug 2020 20:09:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A8=A1=E5=9D=97):=20=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/test/com/test/Test.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 waynboot-generator/src/main/test/com/test/Test.java diff --git a/waynboot-generator/src/main/test/com/test/Test.java b/waynboot-generator/src/main/test/com/test/Test.java new file mode 100644 index 0000000..0de4941 --- /dev/null +++ b/waynboot-generator/src/main/test/com/test/Test.java @@ -0,0 +1,32 @@ +package com.test; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +public class Test { + + private static String name = "E:/data.txt"; + private static final int BSIZE = 1024; + + + public static void main(String[] args) throws IOException { + + // 写入一个文件: + FileChannel fc = new FileOutputStream(name) + .getChannel(); + fc.write(ByteBuffer + .wrap("Some text ".getBytes())); + // 读取文件e: + FileChannel fc2 = new FileInputStream(name) + .getChannel(); + ByteBuffer buff = ByteBuffer.allocate(BSIZE); + fc2.read(buff); + buff.flip(); + while (buff.hasRemaining()) + System.out.write(buff.get()); + System.out.flush(); + } +}