zoukankan      html  css  js  c++  java
  • 《程序员修炼之道》-读书笔记四-NIO复制文件小例子

    第2章 新I/O

    2.2 文件I/O的基石:Path 标准案例-复制文件

    public class SimpleWrite {
        public static void main(String[] args) {

    Path file = Paths.get("D:\mysql-8.0.11-winx64.zip");
    // 读取文件
    byte[] bytes = read(file);
    // 写入文件
    write(bytes);
    }

    public static byte[] read(Path file) {
    byte[] bytes = null;
    List<String> lines = null;
    try {
    // 读取行数据,最好是txt
    // lines = Files.readAllLines(file, StandardCharsets.UTF_8);
    // 什么都能读
    bytes = Files.readAllBytes(file);

    } catch (IOException e) {
    e.printStackTrace();
    }
    return bytes;
    }

    public static void write(byte[] bytes) {
    Path target = Paths.get("D:\test.zip");
    try {
    Files.write(target, bytes);
    // Files.write(target,lines);
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
  • 相关阅读:
    HDU 4005 The war
    #undef
    [转载] #define new DEBUG_NEW
    [转载]常用正则表达式
    [百科]
    [转载]
    [转载]
    [转载]
    [百科]
    [转载]VC6中的文件后缀
  • 原文地址:https://www.cnblogs.com/Deters/p/11157730.html
Copyright © 2011-2022 走看看