日期:2014-05-20 浏览次数:20889 次
public class Directory{
private String file;
public Directory(String filePath){
setFile(filePath);
}
public String getFile() {
return this.file;
}
public void setFile(String filePath) {
try {
FileInputStream in = new FileInputStream(new File("filePath"));
FileChannel fileChannel = in.getChannel();
MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0,
fileChannel.size());
byte[] bytes = new byte[(int) fileChannel.size()];
mappedByteBuffer.get(bytes);
//这里我只是简单的举例处理数据
//假设源文件是文本文件,文件内都是算法加密的文本
//假设有一个算法类Algorithm类有个静态decrypt方法用来还原加密文本
String file = Algorithm.decrypt(bytes.toString());
this.file = file;
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}