`
keren
  • 浏览: 1579738 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

开发平台-文件系统服务

 
阅读更多
//测试本机文件系统
def testLocalFileSystem(){
def localFS = getFileSystem("fs-disk-01");
def path = "/emsflow.log";
def file = localFS.getFile(path);
println("===path:"+file.getPath());
def del = file.delete();
println("===del:"+del);
return null;
}

//测试分布式文件系统
def testHdfsFileSystem(){
def hdfsFS = getFileSystem("fs-hdfs-01");
def path = "local/电影/《唐山大地震 余震》.RMVB";
def file = hdfsFS.getFile(path);
println("===getAbsolutePath:"+file.getAbsolutePath());
println("===getName:"+file.getName());
println("===exists:"+file.exists());
def del = file.delete();
println("===del:"+del);
return null;
}

//测试ftp文件系统
def testFtpFileSystem(){
def ftpFS = getFileSystem("fs-ftp-01");
//def path = "ftptest.log";
//def file = localFS.getFile(path);
//println("===path:"+file.getPath());
//println("===getName:"+file.getName());
//def del = file.delete();
// println("===del:"+del);
def path="/100/WS1/2011/68386F31327A70692D3370/农电〔2010〕15号-关于召开农电半年工作座谈会的通知.doc";
def file = ftpFS.getFile(path);
if(null==file){
file=ftpFS.resolveFile(path);
def create=file.createNewFile();
println("#####不存在文件,创建空文件:"+create);
def jf = new File("D:\\archiveEfile\\100\\WS1\\2011\\68386F31327A70692D3370\\农电〔2010〕15号-关于召开农电半年工作座谈会的通知.doc");
file.setData(new FileInputStream(jf),0);

}else{
println("#####覆盖存在文件#######");
def jf = new File("D:\\archiveEfile\\100\\WS1\\2011\\68386F31327A70692D3370\\农电〔2010〕15号-关于召开农电半年工作座谈会的通知.doc");
file.setData(new FileInputStream(jf),0);
}
println("#####下载文件#######");
file = ftpFS.getFile(path);
def ins=file.getInputStream();
def outs=null;
def byteread=0;
try{
outs = new FileOutputStream("d:/农电〔2010〕15号-关于召开农电半年工作座谈会的通知.doc");   
byte[] buffer = new byte[1204];     
while ((byteread = ins.read(buffer)) != -1) {   
outs.write(buffer, 0, byteread);   
} 
}catch(Exception ex){
ex.printStackTrace();

}
outs.close();
//def del = file.delete();
//println("########del:"+del);
return null;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics