}
return result;
}
}
用java写的一个文件操作类包(5)
时间:2011-02-05 javaeye wakin2003
查看,设置属性:
Java代码
package fileOperation;
import java.io.File;
/**
* 本类实现对文件属性的查看和修改属性的操作。
* @author wakin
*
*/
public class Attribute {
/**
* 查看文件属性。
* @param fileName
*/
public void lookAttribute(String fileName) {
boolean canRead;
boolean canWrite;
boolean canExecute;
File file = new File(fileName);
if(!file.exists())
throw new RuntimeException("File:"+fileName+"is not exist");
canRead = file.canRead();
canWrite = file.canWrite();
canExecute = file.canExecute();
System.out.println("Can read:"+canRead+" Can write:"+canWrite+" Can Execute:"+canExecute);
}
/**
* 根据type值来设置文件的属性 readable为true表示文件可读,ownerOnly为true表示仅对运行本程序的用户有效
* writable为true表示可写,executable为true表示可执行,反之则相反。
* @param fileName
* @param type
* @return
*/
public boolean setAttribute(
String fileName,
boolean readable,
boolean writable,
boolean executable,
boolean ownerOnly)
{
boolean isDone = false;
File file = new File(fileName);
isDone = file.setReadable(readable, ownerOnly)
&& file.setWritable(writable, ownerOnly)
&& file.setExecutable(executable, ownerOnly);
return isDone;
}
}
package fileOperation;
import java.io.File;
/**
* 本类实现对文件属性的查看和修改属性的操作。
* @author wakin
*
*/
public class Attribute {
/**
* 查看文件属性。
* @param fileName
*/
public void lookAttribute(String fileName) {
boolean canRead;
boolean canWrite;
boolean canExecute;
File file = new File(fileName);
if(!file.exists())
throw new RuntimeException("File:"+fileName+"is not exist");
canRead = file.canRead();
canWrite = file.canWrite();
canExecute = file.canExecute();
System.out.println("Can read:"+canRead+"Can write:"+canWrite+"Can Execute:"+canExecute);
}
/**
* 根据type值来设置文件的属性 readable为true表示文件可读,ownerOnly为true表示仅对运行本程序的用户有效
* writable为true表示可写,executable为true表示可执行,反之则相反。
* @param fileName
* @param type
* @return
*/
public boolean setAttribute(
String fileName,
boolean readable,
boolean writable,
boolean executable,
boolean ownerOnly)
{
boolean isDone = false;
File file = new File(fileName);
isDone = file.setReadable(readable, ownerOnly)
&& file.setWritable(writable, ownerOnly)
&& file.setExecutable(executable, ownerOnly);
return isDone;
}
}
用java写的一个文件操作类包(6)
时间:2011-02-05 javaeye wakin2003
查看大小:
J |