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();
        }
  • 相关阅读:
    2.12 使用@DataProvider
    2.11 webdriver中使用 FileUtils ()
    Xcode8 添加PCH文件
    The app icon set "AppIcon" has an unassigned child告警
    Launch Image
    iOS App图标和启动画面尺寸
    iPhone屏幕尺寸、分辨率及适配
    Xcode下载失败 使用已购项目页面再试一次
    could not find developer disk image
    NSDate与 NSString 、long long类型的相互转化
  • 原文地址:https://www.cnblogs.com/xujianbo/p/5099069.html
Copyright © 2011-2022 走看看