hadoop网盘环境搭建,代码全部过程(8)
}
try { } returnb;
//获得连接
ct = new ConnDB().getConn(); //创建statement sm = ct.createStatement();
sm.execute(\
b = true;
values('\+id+\+user+\+emal+\+password+\);
}finally{
this.close();
数据访问层: HdfsDAO.java
publicclass HdfsDAO {
//HDFS访问地址
privatestaticfinal String HDFS = \;
publicHdfsDAO(Configuration conf) { this(HDFS, conf); }
publicHdfsDAO(String hdfs, Configuration conf) { this.hdfsPath = hdfs; this.conf = conf; }
//hdfs路径
private String hdfsPath; //Hadoop系统配置
private Configuration conf;
//启动函数
36 / 53
publicstaticvoid main(String[] args) throws IOException { JobConf conf = config();
HdfsDAO hdfs = new HdfsDAO(conf);
}
//加载Hadoop配置文件 publicstatic JobConf config(){
JobConf conf = newJobConf(HdfsDAO.class); conf.setJobName(\);
conf.addResource(\); conf.addResource(\); conf.addResource(\); returnconf; }
//在根目录下创建文件夹
publicvoidmkdirs(String folder) throws IOException { Path path = new Path(folder);
FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); if(!fs.exists(path)) { fs.mkdirs(path);
System.out.println(\ + folder); } fs.close(); }
//某个文件夹的文件列表
publicFileStatus[] ls(String folder) throws IOException { Path path = new Path(folder);
FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); FileStatus[] list = fs.listStatus(path); System.out.println(\ + folder);
System.out.println(\); if(list != null) for (FileStatus f :list) {
System.out.printf(\大小: %dK\\n\, f.getPath().getName(), (f.isDir()?\目
37 / 53
录\:\文件\), f.getLen()/1024); }
System.out.println(\); fs.close();
returnlist; }
publicvoidcopyFile(String local, String remote) throws IOException { FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); //remote---/用户/用户下的文件或文件夹
fs.copyFromLocalFile(new Path(local), new Path(remote));
System.out.println(\ + local + \ + remote); fs.close(); }
//删除文件或文件夹
publicvoidrmr(String folder) throws IOException { Path path = new Path(folder);
FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); fs.deleteOnExit(path);
System.out.println(\ + folder); fs.close(); }
//下载文件到本地系统
publicvoiddownload(String remote, String local) throws IOException { Path path = new Path(remote);
FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); fs.copyToLocalFile(path, new Path(local));
System.out.println(\ + remote + \ + local); fs.close(); } }
三、功能实现
38 / 53
文件上传功能: (1)选择要上传的文件
(2)上传完毕:
39 / 53
主要代码:
publicclassUploadServletextends HttpServlet { /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
protectedvoiddoGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding(\); String filePath0 = new
String(request.getParameter(\).getBytes(\),\); System.out.println(\+filePath0+\); File file ;
intmaxFileSize = 50 * 1024 *1024; //50M intmaxMemSize = 50 * 1024 *1024; //50M ServletContext context = getServletContext();
String filePath = context.getInitParameter(\); System.out.println(\+filePath+\); // 验证上传内容了类型
String contentType = request.getContentType(); if ((contentType.indexOf(\) >= 0)) {
DiskFileItemFactory factory = newDiskFileItemFactory(); // 设置内存中存储文件的最大值 factory.setSizeThreshold(maxMemSize); // 本地存储的数据大于 maxMemSize. factory.setRepository(new File(\));
40 / 53
…… 此处隐藏:1263字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [政务民生]2013年公共基础知识热点问题(七)
- [政务民生]检验检测机构资质认定评审准则及释义20
- [政务民生]关于印发重庆市房屋建筑和市政基础设施
- [政务民生]1、隧道洞身开挖支护施工技术交底书
- [政务民生]2015年山东省17地市中考语文试题分类汇
- [政务民生]2-高级会计师资格考试和评审流程图
- [政务民生]2018版中国清分机行业发展分析及前景策
- [政务民生]新课改高中政治探究
- [政务民生]2018-2024年中国新型组合房屋行业投资
- [政务民生]2015年上海市春季高考数学模拟试卷五
- [政务民生]灌砂法及环刀法测压实度(带计算过程)
- [政务民生]运筹学实验2求解非线性规划
- [政务民生]劝学、逍遥游默写(教师卷)
- [政务民生]《运筹学》 - 期末考试 - 试卷A - 答案
- [政务民生]八年级英语下册 Module 6 Hobbies测试
- [政务民生]2019年宪法知识竞赛试题库100题(含答
- [政务民生]自动化英文文献翻译
- [政务民生]公文格式实施细则
- [政务民生]高一地理上册课堂跟踪练习题6
- [政务民生]会计继续教育习题及答案
- 第三章 无约束最优化方法
- 泛读教程第三册答案
- 魏晋南北朝文学
- 幂的运算复习题
- 城市环境问题的成因与治理策略_以社会
- 钢结构行业产业链及竞争分析研究
- 新型热塑性弹性体增韧聚丙烯的研究
- 中国旅游地理B卷试题及答案
- (苏教版)五年级数学上册第三单元测试卷
- 不稳定性心绞痛诊断与治疗
- 俞氏国际后勤职能部门绩效考核办法
- GB7258-2017新标准考试题含答案
- 小学生汉字听写比赛活动方案
- 1.3《平抛运动》学案 教科版必修2
- 2011香港特别行政区公务员考试复习资料
- 考虑水力条件变化的城市给水管网可靠性
- 表面活性剂在油田开发和生产中的应用
- ITT内部培训资料-FI端吸泵的介绍
- 文明守纪,从我做起学生发言稿
- 初中读《聊斋志异》心得体会800字范文




