- 浏览: 142259 次
- 性别:
- 来自: 合肥
文章分类
最新评论
-
tjg138:
many thanks!!!!!
Hibernate QBC查询 -
tjg138:
Criteria criteria=session.creat ...
Hibernate QBC查询 -
wa114d:
能不能把你源码放上啊,谢谢啊
Javamail -
cfyme:
重构过的代码 我去运行 怎么也执行不到EmailRunner中 ...
Javamail -
cfyme:
大师,你有没有源文件 你上传附件不是正确的
Javamail
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];
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 inStream
* @param newPath
*/
public void copyFile(InputStream inStream, String newPath) {
try {
int bytesum = 0;
int byteread = 0;
// File oldfile = new File(oldPath);
if (inStream!=null) { //文件存在时
// 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 outStream
* @param fileName
*/
public void downFile(OutputStream outStream,String fileName){
try {
File file=new File(fileName);
InputStream inPut = new FileInputStream(file);
byte[] buf = new byte[1024];
int len = 0;
while((len = inPut.read(buf)) >0)
outStream.write(buf,0,len);
inPut.close();
outStream.close();
} catch (IOException 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);
}
}
发表评论
-
eclipse快捷键
2009-02-03 09:17 1071作用域 功能 快捷键 全局 查找并替换 Ctrl+F 文本 ... -
Java随机码
2009-01-21 10:26 1610package servlet; import java.a ... -
java时间
2009-01-21 10:24 10741. package com.hefeng.test ... -
fastExcel
2009-01-21 10:22 12231. public void testFastExcel ... -
类到底是从哪个Jar包或者目录下装载的
2009-01-11 09:54 948aClass.getProtectionDomain().ge ... -
生成可执行jar文件的教程
2008-12-11 09:27 1030若要生成一个名为 cal.jar 的可执行jar文件:(文件名 ... -
软件智力面试题及答案
2008-08-28 11:29 1185第一组 1.烧一根不均匀的绳,从头烧到尾总共需要1个小时。 ... -
word,excel,pdf
2008-08-28 09:59 10161、一个jacob操作Word的例子,其他操作excel,pd ... -
prototype.js参考
2008-08-22 16:42 1289<!DOCTYPE HTML PUBLIC " ... -
各类Http请求状态(status)及其含义
2008-08-22 16:18 1140AJAX中请求远端文件、或在检测远端文件是否掉链时,都需要了解 ... -
Eclips反编译插件的安装
2008-06-26 09:23 1233大家也许用过其他的反编译工具,比如jad,或者是集成的DJ J ... -
Java反射学习
2008-03-14 10:09 1939Java反射学习 Java反射学 ... -
java性能小知识
2008-02-28 09:47 932Vector v=new Vector(); for(int ... -
qq,msn,skype即时消息
2008-02-19 16:13 1119详细信息请见附件 -
java union and intersection
2008-01-18 09:50 2744String[] arrayA = new String[] ... -
Javamail
2008-01-10 13:20 2377Javamail,论坛上由已经有很多的讨论,但是俺觉得还是不够 ... -
Java中如何正确使用字体编码
2007-12-21 09:16 1227首先声明一下,此文章时从网上转载的。如下的某些方法是确实管 ... -
cvs搭建过程
2007-09-26 11:05 1153一。附件是安装文件 二。建资源库,可在任何地方。 三。set ... -
代码控制来改变应用程序的当前工作目录
2007-09-03 09:34 1078System.setProperty("user.d ... -
java调用存储过程
2007-08-20 09:12 712DBOperator db = new DBOperator( ...
相关推荐
Running from the command line: C# to Java Converter can be launched directly for a specific project, folder, or file conversion from the command line. Command line.(命令行执行) 其他一些特点: 1. ...
To run DJ Java Decompiler setup you must have MS Windows Installer v.1.00 or above installed. (see your \Windows\SYSTEM folder - MSIEXEC.EXE and MSI.DLL). This files are about 2MB. For this reason I ...
- 使用`jar`命令更新MANIFEST.MF文件:`jar cmf manifest_file.jar jar_file_name.jar folder_or_class_files` 4. **使用Inno Setup创建exe安装包**: - Inno Setup是一款免费的Windows安装程序制作工具,它允许...
private static void addFolderToTar(TarArchiveOutputStream out, File fileOrDir, String baseDir) { // ... } ``` 2. **解压缩tar.gz文件**: - 使用`GzipCompressorInputStream`和`TarArchiveInputStream`...
addition, you will need a development environment such as the JDK 1.1.6+ or the Java 2 Platform, Standard Edition (J2SE) 1.2.x or 1.3.x. A general familiarity with object-oriented programming ...
An implementation of Java SE 7 or newer: OpenJDK http://openjdk.java.net/install/ or Sun JDK http://www.oracle.com/technetwork/java/javase/downloads/ or IBM JDK ...
To install tModLoader, extract the zip achive containing this README.txt file to a temporary folder and then simply run the tModLoaderInstaller.jar file in that folder. Java 1.8 or higher is required ...
4. 在"File" -> "Project Structure"中,选择"Modules",然后点击"+" -> "JARs or directories",选择"lib"目录下的Jar包添加进来。 5. 确保在"Dependencies"列表中可以看到你添加的Jar包,如果有多个版本的相同库,...
You can use these functions to insert a file into the current file, delete the active file, send the file through email, or insert a string into the file at every specified increment HTML preview ...
windows_if_you_dont_wanna_install_vcredist is for anyone who don't wana install vcredist, please chose the file for x64 or x86, rename to vcruntime140.dll and copy to BurpUnlimited.jar's folder ...
into a target programming language / executable bundling all the required dependencies in a single file or folder, without requiring a jitter or an external runtime. Why using JTransc? There are a lot...
●扫描目录方式: Audit workbench scan Folder 与其他工具集成: Scan with ANt, Makefile ●编译监控器方式: Fortify SCA Build Monitor FORTIFY Fortify SCA扫描的四个步骤 Fortify SCA扫描总共可以分为四个步骤: ...
KCFinder Features:01 Ajax engine with JSON responses02 Select multiple files with the Ctrl/Command key03 Download multiple files or a folder as single ZIP file04 Clipboard for copying and moving ...
if filename.endswith('.java') or filename.endswith('.py') or filename.endswith('.go') or filename.endswith('.sh'): # 读取文件并处理 ``` 此外,如果代码文件较多,可能需要考虑异步处理,以提高效率。...
After you find a framework file you could pull it via adb pull /path/to/file or use a file manager application. After you have the file locally, pay attention to how Apktool installs it. The number ...
1.8 or above (http://java.com/getjava/) Packet Tracer 7.0 or above Upgrading Activity Grader ------------------------- If there is a previous version of Activity Grader installed, ...
1.8 or above (http://java.com/getjava/) Packet Tracer 7.0 or above Upgrading Activity Grader ------------------------- If there is a previous version of Activity Grader installed, ...
"Select"选择,"Select All"全选,"Find"查找,"Replace"替换,"Folder"是文件夹,"Destination Folder"是目标文件夹,"File"代表文件。"Format Diskette"是格式化磁盘。"Service Pack"是软件更新补丁,用于修复问题...
In a terminal make your way to the folder where the Runner.java and RouteCalculator.java are2. Type "Javac *.java" in that folder containing the files a. If you wish to add additional files in this ...