- 浏览: 1304672 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
kay11:
...
JAVA生成简单的随机字符串(a-zA-Z0-9) -
zhangliguoaccp:
您好关于登录页面的验验证码这块怎么解决的?还有登录成功后,跳转 ...
JAVA,模拟HTTP登录 -
107x:
不错,谢谢!
<c:foreach 循环 map -
wenjin:
不知楼主是不还在想请叫一下我自己开的Tomcat下载一个文件C ...
Android 下载文件及写入SD卡 -
zyywgf:
JSTL c标签,fn标签,fmt标签
package com.potevio.zjhs.util; import java.io.*; import java.awt.Image; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import javax.imageio.ImageIO; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; public class FileOperate { public FileOperate() { } /** * 新建目录 * * @param folderPath * String 如 c:/fqf * @return boolean */ public void newFolder(String folderPath) { try { String filePath = folderPath; filePath = filePath.toString(); java.io.File myFilePath = new java.io.File(filePath); if (!myFilePath.exists()) { myFilePath.mkdir(); } } catch (Exception e) { System.out.println("新建目录操作出错 "); e.printStackTrace(); } } /** * 新建文件 * * @param filePathAndName * String 文件路径及名称 如c:/fqf.txt * @param fileContent * String 文件内容 * @return boolean */ public void newFile(String filePathAndName, String fileContent) { try { String filePath = filePathAndName; filePath = filePath.toString(); File myFilePath = new File(filePath); if (!myFilePath.exists()) { myFilePath.createNewFile(); } FileWriter resultFile = new FileWriter(myFilePath); PrintWriter myFile = new PrintWriter(resultFile); String strContent = fileContent; myFile.println(strContent); resultFile.close(); } catch (Exception e) { System.out.println("新建目录操作出错 "); e.printStackTrace(); } } /** * 删除文件 * * @param filePathAndName * String 文件路径及名称 如c:/fqf.txt * @param fileContent * String * @return boolean */ public void delFile(String filePathAndName) { try { String filePath = filePathAndName; filePath = filePath.toString(); java.io.File myDelFile = new java.io.File(filePath); myDelFile.delete(); } catch (Exception e) { System.out.println("删除文件操作出错 "); e.printStackTrace(); } } /** * 删除文件夹 * * @param filePathAndName * String 文件夹路径及名称 如c:/fqf * @param fileContent * String * @return boolean */ public void delFolder(String folderPath) { try { delAllFile(folderPath); // 删除完里面所有内容 String filePath = folderPath; filePath = filePath.toString(); java.io.File myFilePath = new java.io.File(filePath); myFilePath.delete(); // 删除空文件夹 } catch (Exception e) { System.out.println("删除文件夹操作出错 "); e.printStackTrace(); } } /** * 删除文件夹里面的所有文件 * * @param path * String 文件夹路径 如 c:/fqf */ public void delAllFile(String path) { File file = new File(path); if (!file.exists()) { return; } if (!file.isDirectory()) { return; } String[] tempList = file.list(); File temp = null; for (int i = 0; i < tempList.length; i++) { if (path.endsWith(File.separator)) { temp = new File(path + tempList[i]); } else { temp = new File(path + File.separator + tempList[i]); } if (temp.isFile()) { temp.delete(); } if (temp.isDirectory()) { delAllFile(path + "/ " + tempList[i]);// 先删除文件夹里面的文件 delFolder(path + "/ " + tempList[i]);// 再删除空文件夹 } } } /** * 复制单个文件 * * @param oldPath * String 原文件路径 如:c:/fqf.txt * @param newPath * String 复制后路径 如:f:/fqf.txt * @return boolean */ public void copyFile(String oldPath, String newPath) { try { int bytesum = 0; int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { // 文件存在时 InputStream inStream = new FileInputStream(oldPath); // 读入原文件 FileOutputStream fs = new FileOutputStream(newPath); byte[] buffer = new byte[1444]; int length; while ((byteread = inStream.read(buffer)) != -1) { bytesum += byteread; // 字节数 文件大小 System.out.println(bytesum); fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { System.out.println("复制单个文件操作出错 "); e.printStackTrace(); } } /** * 复制整个文件夹内容 * * @param oldPath * String 原文件路径 如:c:/fqf * @param newPath * String 复制后路径 如:f:/fqf/ff * @return boolean */ public void copyFolder(String oldPath, String newPath) { try { (new File(newPath)).mkdirs(); // 如果文件夹不存在 则建立新文件夹 File a = new File(oldPath); String[] file = a.list(); File temp = null; for (int i = 0; i < file.length; i++) { if (oldPath.endsWith(File.separator)) { temp = new File(oldPath + file[i]); } else { temp = new File(oldPath + File.separator + file[i]); } if (temp.isFile()) { FileInputStream input = new FileInputStream(temp); FileOutputStream output = new FileOutputStream(newPath + "/ " + (temp.getName()).toString()); byte[] b = new byte[1024 * 5]; int len; while ((len = input.read(b)) != -1) { output.write(b, 0, len); } output.flush(); output.close(); input.close(); } if (temp.isDirectory()) {// 如果是子文件夹 copyFolder(oldPath + "/ " + file[i], newPath + "/ " + file[i]); } } } catch (Exception e) { System.out.println("复制整个文件夹内容操作出错 "); e.printStackTrace(); } } /** * 移动文件到指定目录 * * @param oldPath * String 如:c:/fqf.txt * @param newPath * String 如:d:/fqf.txt */ public void moveFile(String oldPath, String newPath) { copyFile(oldPath, newPath); delFile(oldPath); } /** * 移动文件到指定目录 * * @param oldPath * String 如:c:/fqf.txt * @param newPath * String 如:d:/fqf.txt */ public void moveFolder(String oldPath, String newPath) { copyFolder(oldPath, newPath); delFolder(oldPath); } /** * 图片复制 * * @param sourceDir * 源文件目录 * @param targetDir * 目标文件目录 */ public static void copy(String sourceDir, String targetDir) { try { File file = new File(sourceDir); Image image = ImageIO.read(file); int width = image.getWidth(null); int height = image.getHeight(null); BufferedImage imageTag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); imageTag.getGraphics().drawImage(image, 0, 0, width, height, null); FileOutputStream out = new FileOutputStream(targetDir); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(imageTag); out.close(); } catch (IOException e) { e.printStackTrace(); } } /** * 复制图片 * @param sourceDir * @param targetDir */ public void copyImage(String sourceDir, String targetDir) { File _file = new File(sourceDir); // 读入文件 Image src; try { src = javax.imageio.ImageIO.read(_file); // 构造Image对象 int wideth = src.getWidth(null); // 得到源图宽 int height = src.getHeight(null); // 得到源图长 /* * //绘制缩小后的图 BufferedImage tag = new * BufferedImage(wideth/2,height/2,BufferedImage.TYPE_INT_RGB); * tag.getGraphics().drawImage(src,0,0,wideth/2,height/2,null); * //绘制缩小后的图 */ BufferedImage tag = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(src, 0, 0, wideth, height, null); FileOutputStream out = new FileOutputStream(targetDir); // 输出到文件流 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); // JPEG编码 out.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { FileOperate fo = new FileOperate(); String sourceDir = "D:\\Program Files\\Red5\\webapps\\SOSample\\streams\\ZJHS0002_20110226010203.jpg"; String targetDir = "F:/norya/ZJHS0002_20110226010203.jpg"; fo.copyImage(sourceDir, targetDir); } }
发表评论
-
LinkedHashMap
2016-01-13 09:18 610public static void main(Strin ... -
计算星期几,本周的开始结束日期,上一周的开始结束日期
2015-11-04 15:03 1238package com.yinhe.util; imp ... -
java pattern matcher字符串替换
2015-10-28 13:56 842<div class="iteye-blog ... -
jfreechart实现仪表盘dashbord
2015-08-24 17:13 792package com.htcf.dashbord; ... -
java中byte,String,InputStream之间的转换
2012-09-20 17:09 21030import java.io.ByteArrayInpu ... -
StringBuffer清空方法,效率最高
2012-08-10 11:42 1721StringBuffer清空方法大致有4种: Stri ... -
日期大小写转换
2012-07-23 10:53 1850import java.util.Calendar; i ... -
web.xml不认<taglib>解决办法:
2012-07-11 15:24 890在web.xml不认<taglib>解决办法: ... -
VO,PO,TO,BO,POJO,DAO解释
2012-03-20 14:47 1369O/R Mapping:Object Relation ... -
Java 推算日期(计算距今多少年,多少月,多少天的日期)
2011-10-24 16:13 4755import java.text.SimpleDateForm ... -
jdk与jre的区别
2011-07-05 11:31 1168今天突然有朋友问, ... -
JAVA混淆 RetroGuard (转)
2011-06-17 13:28 63411、 下载并将retroguard.jar拷贝 ... -
JavaScript检测上传文件类型
2011-04-22 16:41 1791很实用的一个JS代码,判断一个上传表单允许上传的文件类型,扩展 ... -
id,pid,数据库递归调用展示树形菜单的示例
2011-03-01 15:11 7360public class TreeDAO{ ... -
dtree 树形菜单(checkbox默认选中)
2011-01-24 15:07 5813采用dtree实现树形菜单展示,并有默认checkbox的选中 ... -
Java处理带返回值的存储过程Procedure (SQL Server)
2010-12-27 11:06 4746package com.zjx.test; import ... -
学JAVA很好的一个资源网站
2010-11-19 15:24 1296http://www.verycd.com/topics/93 ... -
某人关于不重复登录的简单处理说明
2010-11-02 13:39 12711.用的是servlet的监听器:(1)用的是HttpSess ... -
java获取资源文件(**.properties)
2010-11-01 15:57 1054import java.io.IOException; im ... -
File delete
2010-10-25 14:11 647/* File file = new File(". ...
相关推荐
文件夹,此时可以通过正常的途径在里面进行创建新文件夹以及进行文件的复制粘贴和删除操作。但文件在此文件夹里面是打不开的需要打开文件需把文件复制出来到其它地方再打开。(此缺陷正在修复当中) 删除文件夹程序...
18.复制文件 19.复制一个文件夹下所有的文件到另一个目录 20.提取扩展名 21.提取文件名 22.提取文件路径 23.替换扩展名 24.追加路径 25.移动文件 26.移动一个文件夹下所有文件到另一个目录 27.指定目录下搜索...
这个类库是一个文件操作类,包括对文件和文件夹创建,复制,移动和删除,有需要对文件操作学习的phper可以参考参考
这个类库是一个文件操作类,包括对文件和文件夹创建,复制,移动和删除
MFC 实现文件操作,包快文件的复制,文件的删除,以及文件的创建等。
C# 文件工具类 实际项目使用 久经考验 文件读写 复制 删除 创建文件夹 判断文件扩展名等等
为其它操作系统文件创建 StarTeam 文件夹 . . . . . 63 使用备选工作文件夹. . . . . . . . . . . . . . . . . 64 更改工作文件夹 . . . . . . . . . . . . . . . . . . . 65 使用视图配置文件中的文件夹属性. . . ....
/T 创建目录结构,但不复制文件。不 包括空目录或子目录。/T /E 包括 空目录和子目录。 /U 只复制已经存在于目标中的文件。 /K 复制属姓。一般的 Xcopy 会重设只读属姓。 /N 用生成的短名复制。 /O 复制文件...
批处理bat文件实现复制、删除、创建文件夹、执行程序、打开文件,批处理bat文件实现复制、删除、创建文件夹、执行程序、打开文件,批处理bat文件实现复制、删除、创建文件夹、执行程序、打开文件
使用Windows API实现,并非调用DOS的DEL COPY命令,支持文件夹的操作,支持*通配符,支持目录树创建,支持强制、非强制(提示)操作。
这个工具是一个命令行工具,用于在文件系统中进行文件和文件夹的创建、删除和使用模板文件。它基于Node.js开发。 创建文件或文件夹:使用mk...使用模板:使用ut命令可以使用指定名称的模板文件创建新的文件或文件夹。
java 文件或文件夹 创建 删除 复制 移动 指定目录等
文件夹的创建将raw中文件放到SD卡中将assets中文件保存到SD卡中压缩包的解压文件的删除功能.rar
PHP文件及文件夹操作之创建、删除、移动、复制_.docx
PHP操作文件类(文件和文件夹创建,复制,移动和删除);挺好用,传上量分享
文件管理器项目,支持文件创建、文件夹创建,文件删除、移动、复制等功能,还有方便方式全选等.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
此文件支持对文件及文件夹结构的多种操作,其中包括: ...有编码方式的文件创建 删除文件 删除文件夹 删除指定文件夹下所有文件 复制单个文件 复制整个文件夹的内容 仅仅拷贝指定路径下的文件夹结构 移动文件 移动目录
基于QT+Linux的简易文件管理器包括文件(夹)的创建删除复制粘贴.zip
文件批量复制替换工具 文件批量替换、文件批量复制、文件按路径复制、文件名列表、文件夹名列表、批量创建文件夹、复制子文件夹文件到根目录、复制多个文件到多个目录、文件查找替换、文件批理查找替换、文件批理...