- 浏览: 119709 次
- 性别:
- 来自: 北京
最新评论
-
NewTamato:
你的这个写的全都是代码,不知道对于flex和spring整合的 ...
Flex+BlazeDS+Spring的一个项目笔记(2) -
agurick:
laowood 写道在不写的一般情况下都是auto吧?自动变量 ...
C中的寄存器变量和引用变量 -
laowood:
agurick 写道补充一下,auto已经过时,已经不再使用。 ...
C中的寄存器变量和引用变量 -
agurick:
补充一下,auto已经过时,已经不再使用。static 变量就 ...
C中的寄存器变量和引用变量 -
ming:
oooooooo
domino如何在数据库中存储信息
一:
//文件原地址
File oldFile = new File("c:/test.xls");
//文件新(目标)地址
String newPath = "c:/test/";
//new一个新文件夹
File fnewpath = new File(newPath);
//判断文件夹是否存在
if(!fnewpath.exists())
fnewpath.mkdirs();
//将文件移到新文件里
File fnew = new File(newPath +oldFile.getName());
oldFile.renameTo(fnew);
二:(使用java复制移动文件 )
/**
* Moving a File to Another Directory
* @param srcFile eg: c:\windows\abc.txt
* @param destPath eg: c:\temp
* @return success
*/
public static boolean move(String srcFile, String destPath){
// File (or directory) to be moved
File file = new File(srcFile);
// Destination directory
File dir = new File(destPath);
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
return success;
}
三:(java删除 移动文件)
File f=new File("c:\\Autoexec.bat");
f.renameTo("d:\\Autoexec.bat");//移动
f.delete();//删除
import java.io.*;
public class MoveFile {
public static void main(String[] args)throws IOException{
File f=new File("d:\\myHomework\\Work");
File fileList[]=f.listFiles();
for(int i=0;i<fileList.length ;i++) {
fileList[i].renameTo(new File("d:\\myHomework\\Backup\\" + fileList[i].getName()));
}
}
四:java操作文件(创建,删除,复制,剪切)
package OALogic.sql.data;
import java.io.*;
public class FileOperate {
public FileOperate() {
}
public static void main(String args[]){
newFolder("D:/100");
}
/**
* 新建目录
* @param folderPath String 如 c:/fqf
* @return boolean
*/
public static 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 static 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 static 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 static 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 static 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 static 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 static 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 static void moveFile(String oldPath, String newPath) {
copyFile(oldPath, newPath);
delFile(oldPath);
}
/**
* 移动文件到指定目录
* @param oldPath String 如:c:/fqf.txt
* @param newPath String 如:d:/fqf.txt
*/
public static void moveFolder(String oldPath, String newPath) {
copyFolder(oldPath, newPath);
delFolder(oldPath);
}
}
//文件原地址
File oldFile = new File("c:/test.xls");
//文件新(目标)地址
String newPath = "c:/test/";
//new一个新文件夹
File fnewpath = new File(newPath);
//判断文件夹是否存在
if(!fnewpath.exists())
fnewpath.mkdirs();
//将文件移到新文件里
File fnew = new File(newPath +oldFile.getName());
oldFile.renameTo(fnew);
二:(使用java复制移动文件 )
/**
* Moving a File to Another Directory
* @param srcFile eg: c:\windows\abc.txt
* @param destPath eg: c:\temp
* @return success
*/
public static boolean move(String srcFile, String destPath){
// File (or directory) to be moved
File file = new File(srcFile);
// Destination directory
File dir = new File(destPath);
// Move file to new directory
boolean success = file.renameTo(new File(dir, file.getName()));
return success;
}
三:(java删除 移动文件)
File f=new File("c:\\Autoexec.bat");
f.renameTo("d:\\Autoexec.bat");//移动
f.delete();//删除
import java.io.*;
public class MoveFile {
public static void main(String[] args)throws IOException{
File f=new File("d:\\myHomework\\Work");
File fileList[]=f.listFiles();
for(int i=0;i<fileList.length ;i++) {
fileList[i].renameTo(new File("d:\\myHomework\\Backup\\" + fileList[i].getName()));
}
}
四:java操作文件(创建,删除,复制,剪切)
package OALogic.sql.data;
import java.io.*;
public class FileOperate {
public FileOperate() {
}
public static void main(String args[]){
newFolder("D:/100");
}
/**
* 新建目录
* @param folderPath String 如 c:/fqf
* @return boolean
*/
public static 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 static 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 static 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 static 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 static 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 static 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 static 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 static void moveFile(String oldPath, String newPath) {
copyFile(oldPath, newPath);
delFile(oldPath);
}
/**
* 移动文件到指定目录
* @param oldPath String 如:c:/fqf.txt
* @param newPath String 如:d:/fqf.txt
*/
public static void moveFolder(String oldPath, String newPath) {
copyFolder(oldPath, newPath);
delFolder(oldPath);
}
}
发表评论
-
redhat 安装 oracle
2013-01-23 12:02 1060装完RHEL5之后遇到的 第一个问题 通过SSH ... -
fedora 14上安装 Oracle 11g
2011-03-31 12:48 4060本文介绍了在Fedora 14 64-bit上安装Or ... -
Flex+BlazeDS+Spring的一个项目笔记(2)
2009-07-30 08:26 3132applicationContext.xml 配置如下 ... -
Flex+BlazeDS+Spring的一个项目笔记(1)
2009-07-29 23:43 1657把最近在做的一个项目的研究成果贴出来做个笔记。项目是要做一个本 ... -
SQL能完成的逻辑都在SQL中
2009-07-21 19:16 1044decode, case的用法 select t.star ... -
Promises don't come easy
2009-05-11 13:48 1135I should have known all along ... -
oracle 9*9乘法口诀表
2009-04-14 18:19 1967select replace(reverse(sys_conn ... -
oracle笔记1
2009-03-31 22:52 1470conn / as sysdba -切换到sys用户 sele ... -
C中的寄存器变量和引用变量
2009-03-25 19:11 5614总共有auto,static,register,extern。 ... -
shell 初步
2009-03-15 18:24 3577ps -ef | grep redis du -sh 查看文件 ... -
File ToBase64String
2009-02-03 15:00 1218public static string Serializ ... -
David Cook - Always Be My Baby
2008-11-05 18:28 1338Studio Version Song ... -
企业应用中C\S是怎样的架构?
2008-10-31 10:19 3985我们公司开发程序一般是 C# Winform 做客户端,EJB ... -
C#画图
2008-10-24 10:06 2373翻出以前刚到公司自己做的这个,以前查资料作了半天,发现 现在 ... -
Can’t find P/Invoke DLL sqlcemeNN.dll
2008-09-01 11:30 2394Can’t find P/Invoke DLL sqlceme ... -
JavaScript replace() 方法
2008-08-27 13:43 2265定义和用法 replace() 方法用于在字符串中 ... -
C# 写Excel 代码
2008-08-20 12:48 10887C# 中使用 Excel using System;usin ... -
开发基于Domino/Notes的动态Web网站
2007-09-27 08:08 1492开发基于Domino/Notes的动态Web网站 用户的需求 ... -
[精华]Linux记事本最常用的命令,迅速掌握Linux
2008-06-28 09:51 4374自己整理的笔记,,适合linux初学者,老手就不要看了,呵呵 ... -
大道至简-java之23种模式一点就通
2008-06-12 10:23 1584一、创建型模式 FACTORY ...
相关推荐
java移动文件.
java文件移动 源码java文件移动 源码java文件移动 源码
通过java移动指定文件夹下的所有文件到目标文件夹下的对应位置,操作简单、方便,非常实用,哈哈哈哈哈哈!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
这个问题要用到java的输入输出流,先用输入流将要复制的文件进行读取,然后给一个变量或者对象,在用输出流将这个变量或者对象的相关内容写到新建的一个File类的对象中,这样就能实现文件的复制和粘贴了 大概的流程就是...
Java 中的一些基本文件操作,包括:文件操作(移动、读写)和文本文件读写
java 移动指定目录下的文件 java 移动指定目录下的文件
用Java编写的文件操作代码,可以在很多地方用到。也可以用来学习Java文件操作。
java操作文件及文件夹 移动、复制、删除文件及文件夹
本文主要介绍了java将文件夹下面的所有的jar文件拷贝到指定的文件夹下面的方法,需要的朋友可以参考下
用java将一个目录内的所有文件移动到另一个目录,默认只移动文件最后修改时间一小时以上的并且名为data_in, data_out,log三个文件夹内的文件,自定义下可移动所有文件,也可以将时间限制修改为0。最后打印操作日志。
移动文件或文件夹 8. 重命名文件/文件夹 9. 查看指定路径下的所有文件的全路径 10. 查看指定路径下的所有文件 11. 列出指定目录下的所有文件对象 12. 上传文件到指定目录 13. 从指定目录下载文件 14....
java 连接 FTP 文件操作(上传,下载,删除,复制
主要介绍了Java快速批量移动文件的实现方法,需要的朋友可以参考下
考虑到文件很多,日志解压、移动文件每解压、移动1000个记录一次,合并、删除文件每合并、删除50000个记录一次, 3. 启动任务前需配置文件解压合并的路径,本程序需配置的路径如下: 1). PROVINCE_DIR:原始文件存放...
9)移动文件 10)可以基于chnSftp对象进行开发 依赖类包在我的sftp包下载下提供 版权声明:本工具类为个人兴趣基于chnSftp编写的应用,个人版权在先,后因各个办公环境无相关软件也有相关的个人使用,和办公环境内的...
java_io_文件操作_复制_删除_移动_下载
java 文件或文件夹 创建 删除 复制 移动 指定目录等
android计算器主要代码,android移动开发课程中计算器java文件
移动mas机API接口说明(java版本),可以通过它开发短信收发程序
JAVA FTP 文件传输 服务端 客户端JAVA FTP 文件传输 服务端 客户端JAVA FTP 文件传输 服务端 客户端