zoukankan      html  css  js  c++  java
  • 将ByteBuffer保存成文件

     String dest = "d:/download/" + name;
    
                Path path = Paths.get(dest).getParent().toAbsolutePath().normalize();
    
                if(!Files.exists(path))
                {
                    try {
                        Files.createDirectories(path);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
    
                try (FileChannel fc = new FileOutputStream(dest).getChannel()){
    
                    ByteBuffer buffer = getResponseAttachment(url);
                    fc.write(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
    import java.io.File;
    import java.io.FileOutputStream;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    
    public class Main {
      public static void main(String[] argv) throws Exception {
        ByteBuffer bbuf = ByteBuffer.allocate(100);
        File file = new File("filename");
    
        boolean append = false;
    
        FileChannel wChannel = new FileOutputStream(file, append).getChannel();
    
        wChannel.write(bbuf);
    
        wChannel.close();
      }
    }
    String dest = "d:/download/" + name;
                try (FileChannel fc = FileChannel.open(Paths.get(dest), StandardOpenOption.WRITE)){
                    ByteBuffer buffer = getResponseAttachment(url);
                    fc.write(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
  • 相关阅读:
    ajax(ajax开发)
    gnuplot常用技巧
    Gunplot 命令大全
    程序员的绘图利器 — Gnuplot
    什么是 gnuplot
    QT正则表达式---针对IP地址
    JSP实现分页功能
    java.lang.OutOfMemoryError: Java heap space错误及处理办法
    getInitParameter()
    C/S软件的自动升级部署
  • 原文地址:https://www.cnblogs.com/passedbylove/p/11462112.html
Copyright © 2011-2022 走看看