Java文件操作大全(四)
26.移动一个文件夹下所有文件到另一个目录
//import java.io.*;
File movefile=new File(%%1);
File[] movefiles=movefile.listFiles();
for(int i=0;i<movefiles.length;i++){
if(movefiles[i].isFile()){
int bytesum = 0;
int byteread = 0;
File oldfile = new File(movefiles[i]);
try {
if (oldfile.exists()) { //文件存在时
InputStream inStream = new FileInputStream(oldfile); //读入原文件
FileOutputStream fs = new FileOutputStream(new File(%%2,oldfile.getName()));
byte[] buffer = new byte[5120];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
//System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
inStream.close();
oldfile.delete();
}
}
catch (Exception e) {
System.out.println("复制单个文件操作出错");
e.printStackTrace();
}
}
}
27.指定目录下搜索文件
//import java.io.*;
String filter="*.*";
String path=%%1;
File file = new File(path);
if(file.exists()) {
if(file.isDirectory()) {
File[] fileArray = file.listFiles();
for(File f:fileArray) {
if(f.isDirectory()) {
doSearch(filter,f.getPath());
} else {
if(f.getName().indexOf(filter) >= 0) {
countFiles++;
result.append(f.getPath() + "\r\n");
}
}
statusShow1.setText(f.getPath());
}
statusShow2.setText("The numbers of files had been found:" + countFiles);
&nb
相关文档:
在c中enum的使用和struct很像
enum name{
a,b,c
};
struct name{
int a;
int b;
char c;
};
or
typedef struct{
int a;
int b;
char c;
}Name;
使用的时候都要先声明变量
enum name n1,n2,n3;
n1=a;
n2=b;
n3=enum name(3-1);
struct name sn1,sn2;
s ......
/由于JAVA语言的数据类型都是有符号类型,而C# C++一般数据类型都是分有符号和无符号,
//因此在通信过程中传递的Byte[]无法直
接转换成C#需要的类型,
//以前倒是没注意这些细节,因为一般用一种语言编程,
//大都有内置的转换方法。跨语言环境的转换就的自己动
手想办法了。
1、java的Byte[]转换成c#的Int32
privat ......
一,什么是异常
当出现程序无法控制的外部环境问题(用户提供的文件不存在,文件内容损坏,网络不可用...)时,JAVA就会用异常对象来描述。
JAVA中用2种方法处理异常:
1.在发生异常的地方直接处理;
2.将异常抛给调用者,让调用者处理。
JAVA异常可分为3种:
(1)检查性异常:jav ......
Mediator 模式的目的是定义一个对象,封装一组对象间的交互,这样就降低了交互对象间的耦合,使对象和他们参考的对象显示地分离,就可以独立地变化他们之间的关系.
条件:对象间的交互和对象的其他行为比较独立.
  ......
11.写入属性
//import java.io.*;
File filereadonly=new File(%%1);
try {
boolean b=filereadonly.setReadOnly();
}
catch (Exception e) {
System.out.println("拒绝写访问:"+e.printStackTrace());
}
12.枚举一个文件夹中的所有文件
//import  ......