zoukankan      html  css  js  c++  java
  • 文件移动与下载

    /**
         * 
         * 移动文件
         * @param oldFileName 旧文件的全路径 
         * @param newFilePath 目标文件夹
       * @param newFileName 新文件的全路径   *
    @see [类、类#方法、类#成员] */ public static void moveFile(String oldFileName, String newFilePath) { File oldFile = new File(oldFileName); File fnewpath = new File(newFilePath); if (!fnewpath.exists()) fnewpath.mkdirs(); File fnew = new File(new StringBuffer().append(newFilePath).append(oldFile.getName()).toString()); oldFile.renameTo(fnew); } public static void moveFile(String oldFileName, String newFilePath,String newFileName) { File oldFile = new File(oldFileName); File fnewpath = new File(newFilePath); if (!fnewpath.exists()) fnewpath.mkdirs(); File fnew = new File(new StringBuffer().append(newFilePath).append(newFileName).toString()); oldFile.renameTo(fnew); }
    /**
         * 下载文件
         * @param urlString 文件地址
         * @param filename 保存文件名
         * @param savePath 保存文件夹
         * @throws Exception
         * @see [类、类#方法、类#成员]
         */
        public static void download(String urlString, String filename, String savePath)
            throws Exception
        {
            URL url = new URL(urlString);
            URLConnection con = url.openConnection();
            con.setConnectTimeout(5 * 1000);
            InputStream is = con.getInputStream();
            byte[] bs = new byte[1024];
            int len;
            File sf = new File(savePath);
            if (!sf.exists())
            {
                sf.mkdirs();
            }
            OutputStream os = new FileOutputStream(sf.getPath() + File.separator + filename);
            while ((len = is.read(bs)) != -1)
            {
                os.write(bs, 0, len);
            }
            os.close();
            is.close();
        }
  • 相关阅读:
    hadoop运维
    HBase Master启动过程
    bulk-load 装载HDFS数据到HBase
    HBase开启LZO
    Hash函数
    swift菜鸟入门视频教程-02-基本运算符
    当当网-前端project师測试题
    VB.NET & DataGridView与数据库的连接
    Hadoop-2.2.0中文文档—— Common
    PHP 获取数组随意下标key的上一个prev和下一个next下标值
  • 原文地址:https://www.cnblogs.com/xujianbo/p/5099069.html
Copyright © 2011-2022 走看看