├── .DS_Store ├── Cookie_learn ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── .jsdtscope │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.wst.common.component │ ├── org.eclipse.wst.common.project.facet.core.xml │ ├── org.eclipse.wst.jsdt.ui.superType.container │ └── org.eclipse.wst.jsdt.ui.superType.name └── WebContent │ ├── META-INF │ └── MANIFEST.MF │ ├── WEB-INF │ └── web.xml │ ├── app_1 │ ├── index.jsp │ └── login.jsp │ └── app_2 │ ├── book.jsp │ └── books.jsp ├── README.md └── hadoop_yuapn_test ├── .classpath ├── .gitignore ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container └── org.eclipse.wst.jsdt.ui.superType.name ├── WebContent ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ ├── lib │ │ ├── commons-fileupload-1.3.1.jar │ │ ├── commons-io-2.4.jar │ │ └── mysql-connector-java-5.1.7-bin.jar │ └── web.xml └── index.jsp └── src └── com ├── controller └── UploadServlet.java └── model ├── HdfsDAO.java └── test.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swan815/UndergraduateCourseProjects/9593c834b8e008977cdd9093025ad932386f7b43/.DS_Store -------------------------------------------------------------------------------- /Cookie_learn/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Cookie_learn/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /Cookie_learn/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Cookie_learn 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /Cookie_learn/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Cookie_learn/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /Cookie_learn/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Cookie_learn/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Cookie_learn/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /Cookie_learn/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /Cookie_learn/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /Cookie_learn/WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Cookie_learn 4 | 5 | index.html 6 | index.htm 7 | index.jsp 8 | default.html 9 | default.htm 10 | default.jsp 11 | 12 | -------------------------------------------------------------------------------- /Cookie_learn/WebContent/app_1/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | <% 11 | String name = request.getParameter("name"); 12 | //out.print(name); 13 | if(name != null && !name.trim().equals("")){ 14 | Cookie cookie = new Cookie("name",name); 15 | cookie.setMaxAge(30); 16 | response.addCookie(cookie); 17 | }else{ 18 | Cookie [] cookies = request.getCookies(); 19 | if(cookies != null && cookies.length>0){ 20 | for(Cookie cookie : cookies){ 21 | String cookieName=cookie.getName(); 22 | if("name".equals(cookieName)){ 23 | String val=cookie.getValue(); 24 | name=val; 25 | } 26 | } 27 | } 28 | } 29 | 30 | if(name != null && !name.trim().equals("")){ 31 | out.print("Hello: "+ name); 32 | }else{ 33 | response.sendRedirect("login.jsp"); 34 | } 35 | %> 36 | 37 | 38 | -------------------------------------------------------------------------------- /Cookie_learn/WebContent/app_1/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |
11 | 12 | name: 13 | 14 | 15 | 16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /Cookie_learn/WebContent/app_2/book.jsp: -------------------------------------------------------------------------------- 1 | <%@page import="java.util.ArrayList"%> 2 | <%@page import="java.util.List"%> 3 | <%@ page language="java" contentType="text/html; charset=UTF-8" 4 | pageEncoding="UTF-8"%> 5 | 6 | 7 | 8 | 9 | Insert title here 10 | 11 | 12 |

13 | Book Detail Page 14 |

15 | Book:<%= request.getParameter("book") %> 16 |

17 | 18 | Return 19 | 20 | <% 21 | String book=request.getParameter("book"); 22 | 23 | Cookie [] cookies = request.getCookies(); 24 | List bookCookies=new ArrayList(); 25 | Cookie tempCookie=null; 26 | if(cookies != null && cookies.length > 0){ 27 | for(Cookie c: cookies){ 28 | String cookieName=c.getName(); 29 | if(cookieName.startsWith("LSY_BOOK")){ 30 | bookCookies.add(c); 31 | 32 | if(c.getValue().equals(book)){ 33 | tempCookie=c; 34 | } 35 | } 36 | } 37 | 38 | } 39 | 40 | if(bookCookies.size() >= 5 && tempCookie == null){ 41 | tempCookie = bookCookies.get(0); 42 | } 43 | 44 | if(tempCookie != null){ 45 | tempCookie.setMaxAge(0); 46 | response.addCookie(tempCookie); 47 | } 48 | 49 | 50 | Cookie cookie = new Cookie("LSY_BOOK"+book,book); 51 | response.addCookie(cookie); 52 | %> 53 | 54 | 55 | -------------------------------------------------------------------------------- /Cookie_learn/WebContent/app_2/books.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | 11 |

Books Pages

12 | 13 | Java Web

14 | Java

15 | Oracle

16 | Ajax

17 | JavaScript

18 | Android

19 | Jbpm

20 | Struts

21 | Hibernate

22 | Spring

23 | 24 |

25 | <% 26 | Cookie [] cookies = request.getCookies(); 27 | 28 | if(cookies != null && cookies.length > 0){ 29 | for(Cookie c: cookies){ 30 | String cookieName=c.getName(); 31 | if(cookieName.startsWith("LSY_BOOK")){ 32 | out.println(c.getValue()); 33 | out.print("
"); 34 | } 35 | } 36 | } 37 | 38 | %> 39 | 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 本科课设相关项目 2 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hadoop_yuapn_test 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /hadoop_yuapn_test/.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /hadoop_yuapn_test/WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/WebContent/WEB-INF/lib/commons-fileupload-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swan815/UndergraduateCourseProjects/9593c834b8e008977cdd9093025ad932386f7b43/hadoop_yuapn_test/WebContent/WEB-INF/lib/commons-fileupload-1.3.1.jar -------------------------------------------------------------------------------- /hadoop_yuapn_test/WebContent/WEB-INF/lib/commons-io-2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swan815/UndergraduateCourseProjects/9593c834b8e008977cdd9093025ad932386f7b43/hadoop_yuapn_test/WebContent/WEB-INF/lib/commons-io-2.4.jar -------------------------------------------------------------------------------- /hadoop_yuapn_test/WebContent/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swan815/UndergraduateCourseProjects/9593c834b8e008977cdd9093025ad932386f7b43/hadoop_yuapn_test/WebContent/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar -------------------------------------------------------------------------------- /hadoop_yuapn_test/WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Session_Learn 4 | 5 | index.html 6 | index.htm 7 | index.jsp 8 | default.html 9 | default.htm 10 | default.jsp 11 | 12 | 13 | 14 | UploadServlet 15 | UploadServlet 16 | com.controller.UploadServlet 17 | 18 | 19 | Location to store uploaded file 20 | file-upload 21 | 22 | /Users/apple/Documents/Tomcat8/apache-tomcat-8.0.36/webapps 23 | 24 | 25 | 26 | UploadServlet 27 | /UploadServlet 28 | 29 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/WebContent/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 |
11 |
12 | 13 |
14 |
15 | 16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /hadoop_yuapn_test/src/com/controller/UploadServlet.java: -------------------------------------------------------------------------------- 1 | package com.controller; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | 8 | import javax.servlet.ServletContext; 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServlet; 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | import org.apache.commons.fileupload.DiskFileUpload; 15 | import org.apache.commons.fileupload.FileItem; 16 | import org.apache.commons.fileupload.disk.DiskFileItemFactory; 17 | import org.apache.commons.fileupload.servlet.ServletFileUpload; 18 | 19 | 20 | 21 | /** 22 | * Servlet implementation class UploadServlet 23 | */ 24 | public class UploadServlet extends HttpServlet { 25 | 26 | /** 27 | * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 28 | */ 29 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 30 | this.doPost(request, response); 31 | } 32 | 33 | /** 34 | * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 35 | */ 36 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 37 | request.setCharacterEncoding("UTF-8"); 38 | File file ; 39 | int maxFileSize = 50 * 1024 *1024; //50M 40 | int maxMemSize = 50 * 1024 *1024; //50M 41 | ServletContext context = getServletContext(); 42 | String filePath = context.getInitParameter("file-upload"); 43 | System.out.println("source file path:"+filePath+""); 44 | // 验证上传内容了类型 45 | String contentType = request.getContentType(); 46 | if ((contentType.indexOf("multipart/form-data") >= 0)) { 47 | 48 | DiskFileItemFactory factory = new DiskFileItemFactory(); 49 | // 设置内存中存储文件的最大值 50 | factory.setSizeThreshold(maxMemSize); 51 | // 本地存储的数据大于 maxMemSize. 52 | factory.setRepository(new File("c:\\temp")); 53 | 54 | // 创建一个新的文件上传处理程序 55 | ServletFileUpload upload = new ServletFileUpload(factory); 56 | // 设置最大上传的文件大小 57 | upload.setSizeMax(maxFileSize); 58 | try{ 59 | // 解析获取的文件 60 | List fileItems = upload.parseRequest(request); 61 | 62 | // 处理上传的文件 63 | Iterator i = fileItems.iterator(); 64 | 65 | System.out.println("begin to upload file to tomcat server

"); 66 | while (i.hasNext () ) 67 | { 68 | FileItem fi = (FileItem)i.next(); 69 | if (!fi.isFormField () ) 70 | { 71 | // 获取上传文件的参数 72 | String fieldName = fi.getFieldName(); 73 | String fileName = fi.getName(); 74 | 75 | String fn = fileName.substring(fileName.lastIndexOf("\\")+1); 76 | System.out.println("
"+fn+"
"); 77 | boolean isInMemory = fi.isInMemory(); 78 | long sizeInBytes = fi.getSize(); 79 | // 写入文件 80 | if(fileName.lastIndexOf("\\") >= 0 ){ 81 | file = new File( filePath , 82 | fileName.substring(fileName.lastIndexOf("\\"))) ; 83 | //out.println("filename"+fileName.substring( fileName.lastIndexOf("\\"))+"||||||"); 84 | }else{ 85 | file = new File( filePath , 86 | fileName.substring(fileName.lastIndexOf("\\")+1)) ; 87 | } 88 | fi.write(file) ; 89 | System.out.println("upload file to tomcat server success!"); 90 | 91 | 92 | } 93 | } 94 | }catch(Exception ex) { 95 | System.out.println(ex); 96 | } 97 | }else{ 98 | System.out.println("

No file uploaded

"); 99 | 100 | } 101 | 102 | 103 | 104 | } 105 | 106 | } -------------------------------------------------------------------------------- /hadoop_yuapn_test/src/com/model/HdfsDAO.java: -------------------------------------------------------------------------------- 1 | package com.model; 2 | 3 | import java.io.IOException; 4 | import java.net.URI; 5 | 6 | import org.apache.hadoop.conf.Configuration; 7 | import org.apache.hadoop.fs.FileStatus; 8 | import org.apache.hadoop.fs.FileSystem; 9 | import org.apache.hadoop.fs.Path; 10 | import org.apache.hadoop.mapred.JobConf; 11 | 12 | public class HdfsDAO { 13 | 14 | // HDFS 访问地址 15 | private static final String HDFS = "hdfs://localhost:9000"; 16 | 17 | public HdfsDAO(Configuration conf) { 18 | this(HDFS, conf); 19 | } 20 | 21 | public HdfsDAO(String hdfs, Configuration conf) { 22 | this.hdfsPath = hdfs; 23 | this.conf = conf; 24 | } 25 | 26 | // hdfs 路径 27 | private String hdfsPath; 28 | // Hadoop 系统配置 29 | private Configuration conf; 30 | 31 | // 启动函数 32 | public static void main(String[] args) throws IOException { 33 | JobConf conf = config(); 34 | HdfsDAO hdfs = new HdfsDAO(conf); 35 | hdfs.mkdirs("/Tom"); 36 | // hdfs.copyFile("C:\\files", "/wgc/"); 37 | // hdfs.ls("hdfs://localhost:9000/input"); 38 | // hdfs.rmr("/wgc/files"); 39 | // hdfs.download("/wgc/(3)windows 下 hadoop+eclipse 环境搭建. docx", "c:\\"); 40 | System.out.println("success!"); 41 | } 42 | 43 | // 加载 Hadoop 配置文件 44 | public static JobConf config() { 45 | JobConf conf = new JobConf(HdfsDAO.class); 46 | conf.setJobName("HdfsDAO"); 47 | conf.addResource("classpath:/hadoop/core-site.xml"); 48 | conf.addResource("classpath:/hadoop/hdfs-site.xml"); 49 | conf.addResource("classpath:/hadoop/mapred-site.xml"); 50 | return conf; 51 | } 52 | 53 | // 在根目录下创建文件夹 54 | public void mkdirs(String folder) throws IOException { 55 | Path path = new Path(folder); 56 | FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); 57 | if (!fs.exists(path)) { 58 | fs.mkdirs(path); 59 | System.out.println("Create:" + folder); 60 | } 61 | fs.close(); 62 | } 63 | 64 | // 某个文件夹的文件列表 65 | public FileStatus[] ls(String folder) throws IOException { 66 | Path path = new Path(folder); 67 | FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); 68 | FileStatus[] list = fs.listStatus(path); 69 | System.out.println("ls:" + folder); 70 | System.out.println("=========================================================="); 71 | if (list != null) 72 | for (FileStatus f : list) { 73 | // System.out.printf("name: %s, folder: %s, size: %d\n", 74 | // f.getPath(), f.isDir(), f.getLen()); 75 | System.out.printf("%s, folder: %s, 大小: %dK\n", f.getPath().getName(), (f.isDir() ? "目录" : "文件"), 76 | f.getLen() / 1024); 77 | } 78 | System.out.println("=========================================================="); 79 | fs.close(); 80 | 81 | return list; 82 | } 83 | 84 | public void copyFile(String local, String remote) throws IOException { 85 | FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); 86 | // remote---/ 用户 / 用户下的文件或文件夹 87 | fs.copyFromLocalFile(new Path(local), new Path(remote)); 88 | System.out.println("copy from:" + local + "to" + remote); 89 | fs.close(); 90 | } 91 | 92 | // 删除文件或文件夹 93 | public void rmr(String folder) throws IOException { 94 | Path path = new Path(folder); 95 | FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); 96 | fs.deleteOnExit(path); 97 | System.out.println("Delete:" + folder); 98 | fs.close(); 99 | } 100 | 101 | // 下载文件到本地系统 102 | public void download(String remote, String local) throws IOException { 103 | Path path = new Path(remote); 104 | FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf); 105 | fs.copyToLocalFile(path, new Path(local)); 106 | System.out.println("download: from" + remote + "to" + local); 107 | fs.close(); 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /hadoop_yuapn_test/src/com/model/test.java: -------------------------------------------------------------------------------- 1 | package com.model; 2 | 3 | import java.net.URI; 4 | 5 | import org.apache.hadoop.conf.Configuration; 6 | import org.apache.hadoop.fs.FileSystem; 7 | 8 | public class test { 9 | 10 | String uri = "hdfs://10.1.14.24:9000/"; 11 | Configuration conf = new Configuration(); 12 | //FileSystem fs = FileSystem.get(URI.create(uri), conf); 13 | 14 | } 15 | --------------------------------------------------------------------------------