• 文件移动与下载


    /**
         * 
         * 移动文件
         * @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();
        }
  • 相关阅读:
    Unbuntu--安装VMware Tools
    方法引用的基本使用
    Stream流
    Stream流的常用方法
    枚举
    编程式路由导航
    向路由组件传递数据
    缓存路由组件
    嵌套路由
    基本路由
  • 原文地址:https://www.cnblogs.com/xujianbo/p/5099069.html
Copyright © 2020-2023  润新知