- 浏览: 1523883 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (532)
- 软件设计师 (7)
- PSP (5)
- NET MD (9)
- Hibernate (8)
- DIY (51)
- Work (43)
- GAME (24)
- 未分类 (44)
- iPod (6)
- MySQL (39)
- JSP (7)
- 日语能力考试 (36)
- 小说 (4)
- 豆包网 (23)
- 家用电脑 (7)
- DB2 (36)
- C/C++ (18)
- baby (9)
- Linux (13)
- thinkpad (23)
- OA (1)
- UML (6)
- oracle (24)
- 系统集成 (27)
- 脑梗塞 (6)
- 车 (8)
- MainFrame (8)
- Windows 7 (13)
- 手机 (8)
- git (12)
- AHK (2)
- COBOL (2)
- Java (9)
最新评论
-
安静听歌:
... ...
UUID做主键,好还是不好?这是个问题。 -
lehehe:
http://www.haoservice.com/docs/ ...
天气预报 -
lehehe:
[url http://www.haoservice.com/ ...
天气预报 -
liubang201010:
监控TUXEDO 的软件推荐用这个,专业,权威.并能提供报警和 ...
(转载)Tuxedo中间件简介 -
tinkame:
Next[j] =-1 当j=0时;=Max{k|0<k ...
KMP字符串模式匹配详解
package File;
import java.io.*;
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];
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 args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
FileOperate f=new FileOperate();
f.copyFile("g:\\电影\\crazy stone.wmv", "g:\\222.wmv");
}
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1255433
发表评论
-
(转)SQLデータ型
2011-08-24 18:09 2111https://www.microfocus. ... -
(转)Determining equivalent SQL and COBOL data types
2011-08-24 18:01 1450http://publib.boulder.ibm ... -
(转)grep Programs and Regular expressions
2011-08-10 13:10 1180http://ss64.com/bash/grep-r ... -
(转)find:根据指定条件查找文件
2011-08-10 11:34 1005http://man.ddvip.com/ ... -
(转)[红旗] 手动可以执行,加入crontab 就不行了
2011-07-05 13:07 1770http://bbs.chinaunix.net ... -
(转)Linux——计划任务管理
2011-07-04 15:02 1534http://hi.baidu.com/%BA%CE%B4 ... -
(转)CentOS的计划任务,Crontab安装及使用方法
2011-07-04 15:01 3077http://www.hitsword.org/re ... -
(转)Windows如何压缩tar.gz格式
2011-05-11 10:34 1245http://www.viosem.com/2008/ ... -
(转)日语的文字编码
2011-03-02 10:23 1618http://blog.csdn.net/jackyren ... -
(转)《软件工程的事实与谬论》
2010-11-04 09:57 1645http://book.group.iteye.com ... -
(转)VB6迁移到VB.NET的一些问题汇总
2010-11-03 15:02 1765http://www.cnblogs.com/ols/ar ... -
(转)《张冰Java视频教程》(struts Hibernate spring jsp J2SE)长期更新
2010-07-14 20:51 0http://www.verycd.com/topics/ ... -
(转)使用httpclient4登录百度
2010-02-26 14:45 0http://legend30g-4/article/h ... -
(转)如何一次性从Outlook Express中导出邮件
2010-01-06 13:23 5625http://hi.baidu.com/grape17/b ... -
Top Ten TPC-E by Performance
2009-10-21 14:50 1016http://www.tpc.org/tpc ... -
IBM DB2 UDB 和 SQL Server 2000
2009-10-21 14:49 1328http://www.microsoft.com/chin ... -
TCP/IP環境のPCからメインフレームを使用する
2009-10-16 11:51 0http://cap-l.sakushin-u.ac.jp:8 ... -
JP1名词解释
2009-10-10 15:17 3251http://soft.yesky.com/0/30685 ... -
Java 内存溢出的可能性汇总
2009-02-18 13:42 15411 分配的内存太小, 请使用 JVM 参数设置更大的可用内存 ... -
Java web应用内存溢出 [已结帖,结帖人:pengble]
2009-02-18 13:40 2254加为好友发送私信在线聊天
相关推荐
java文件读写操作大全java文件读写操作大全java文件读写操作大全java文件读写操作大全java文件读写操作大全
# java实现对文件的各种操作的工具类 ## 可以实现的操作有: 1. 删除单个文件 2. 删除文件夹及文件夹下的文件 3. 使用文件流对单个文件进行复制 4. 复制整个文件夹内容(包含子文件夹中的所有内容) 5. ...
自己用java编写的一个模拟DOS文件目录操作的小程序。有dir, cd, cd/, cd.., md, rd等功能。
java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java文件操作类java...
我自己搜集的用java写的操作文件和目录的程序,挺全的
io java 文件操作 命令 全部 io java 文件操作 命令 全部 io java 文件操作 命令 全部 io java 文件操作 命令 全部
Java文件操作大全
java文件操作总结 详细介绍 java对文件的操作 每个都有对应的例子
java操作Excel文件java操作Excel文件java操作Excel文件java操作Excel文件java操作Excel文件java操作Excel文件java操作Excel文件
java视频教程 Java文件操作 JavaFile
eclipse插件,打开java文件目录
java读取共享文件使用jcifs-1.1.11.jar 的SmbFile 类使用用户名密码共享目录操作共享文件
Apache Commons IO提供拷贝文件方法在其FileUtils类,可用于复制一个文件到另一个地方
内容包括java语言对文件和文件夹的各种操作
用java8实现一个文件目录的监听,目录中文件创建、修改、删除等操作
一些较为全面的java的文件操作的代码,在学习中有极大地帮助!!
非常全的java文件操作说明、示例,欢迎下载共同学习
这个文件里面包含了java的IO流对文件的操作和java通道加内存映射对文件操作的源码
Java文件操作封装类
java中文件操作大全 覆盖大部分对文件操作的基本代码