一、安装java

二、IntelliJ IDEA(2018)安装和破解与初期配置 参考链接

1.进入官网下载IntelliJ IDEA https://www.jetbrains.com/idea/download/#section=windows,选择收费版,下面再破解

2.点击下载进入下载页开始下载,如果没有弹出下载框,请点击图中位置

3.下载之后双击,开始安装,点击next

4.选择安装路径,最好不要安装到C盘,这里我安装到D盘IDEA文件夹,点击next

5.选择安装32位或者64位的,根据你电脑选择,点击next

6.这里默认就行了,点击install

7.开始安装

.

8.安装完成,勾选启动

9.点击OK

.

10.点击接受

11.破解

1.下载破解补丁JetbrainsCrack-2.6.2.jar 地址:http://download.csdn.net/detail/gnail_oug/9824630

或者 http://idea.lanyus.com/

2.将你下载好的JetbrainsCrack-2.6.2.jar拷贝到你的Idea安装目录的bin目录下,如下图红色框所示

3.在安装的idea下面的bin目录下面有2个文件 : 一个是idea64.exe.vmoptions,还有一个是idea.exe.vmoptions(如上图绿框)。

用记事本打开 分别在最下面一行增加一行:-javaagent:D:\IDEA\bin\JetbrainsCrack-2.6.2.jar

注意:“D:\IDEA\bin\JetbrainsCrack-2.6.2.jar”是我对应的JetbrainsCrack-2.6.2.jar的位置,你用你自己的安装路径。

4.重新启动软件,再到Acrivation code中选择界面的时候,写入下面注册代码(到2099年到期)

  1. ThisCrackLicenseId-{
  2. "licenseId":"ThisCrackLicenseId",
  3. "licenseeName":"idea",
  4. "assigneeName":"",
  5. "assigneeEmail":"idea@163.com",
  6. "licenseRestriction":"For This Crack, Only Test! Please support genuine!!!",
  7. "checkConcurrentUse":false,
  8. "products":[
  9. {"code":"II","paidUpTo":"2099-12-31"},
  10. {"code":"DM","paidUpTo":"2099-12-31"},
  11. {"code":"AC","paidUpTo":"2099-12-31"},
  12. {"code":"RS0","paidUpTo":"2099-12-31"},
  13. {"code":"WS","paidUpTo":"2099-12-31"},
  14. {"code":"DPN","paidUpTo":"2099-12-31"},
  15. {"code":"RC","paidUpTo":"2099-12-31"},
  16. {"code":"PS","paidUpTo":"2099-12-31"},
  17. {"code":"DC","paidUpTo":"2099-12-31"},
  18. {"code":"RM","paidUpTo":"2099-12-31"},
  19. {"code":"CL","paidUpTo":"2099-12-31"},
  20. {"code":"PC","paidUpTo":"2099-12-31"}
  21. ],
  22. "hash":"2911276/0",
  23. "gracePeriodDays":7,
  24. "autoProlongated":false}

  

5.能够进入应用界面,说明破解成功(如果还不成功去http://idea.lanyus.com/这个网站看一下)

12.配置 File >> Settings... (Ctrl + Alt + S)

1.关闭reopen选项,打开Intellij IDEA 时不会默认打开上次关闭的项目

2.安装maven

2.1 解压apache-maven-3.3.9文件夹放到D盘根目录  apache-maven-3.3.9压缩文件下载

2.1修改maven的settings.xml配置,在apache-maven-3.3.9/conf/settings.xml 已经配置好了,直接使用即可

2.2 在D盘目录下,创建一个m2文件夹

2.3 将刚才修改后的settings.xml文件移动到该m2文件夹下

2.4 修改idea中关于maven的配置(检查setttings和defaultSettings中的maven设置是否一样)

3.项目编码设置(一共6处修改)

File >> Settings ...
File >> Other settings >> Settings for New Projects ...

4.创建项目

设置JDK主目录路径

File >> Projects structure ... (Ctrl + Shift + Alt + S)  >>  如下两图,设置你自己java的安装路径


5.导入依赖

View >>  Tool windows >> Maven Projects


6.常用快捷键

ctrl + shift + enter:补全代码后方缺失的符号
shift + enter:直接换行
ctrl + alt + t:弹出可以包裹当前代码的语法列表
alt + enter:相当于eclipse的ctrl + 1,错误智能修复提示
ctrl + p:提示当前方法可以传递的参数类型以及参数个数
ctrl + d:复制当前行到下一行,类似eclipse中的ctrl + alt + 光标下
ctrl + x:剪切当前光标所在行
ctrl + y:删除当前光标所在行
ctrl + shift + 光标上或下:移动当前行代码
ctrl + alt + 光标左右:可以在查看代码的时候,切换上一次或下一次查看的视图
ctrl + o::弹出当前类中可以覆写的方法列表
ctrl + alt + v:生成一个变量接受某个方法返回的值

ctrl + shift + i : 查看方法定义代码

HDFS中的常用API操作

在项目中创建一个HDFSClient的java类

  1. import org.apache.hadoop.conf.Configuration;
  2. import org.apache.hadoop.fs.*;
  3. import org.apache.hadoop.io.IOUtils;
  4. import org.junit.Test;
  5.  
  6. import java.io.IOException;
  7. import java.net.URI;
  8. import java.net.URISyntaxException;
  9.  
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import java.io.FileOutputStream;
  13.  
  14. /*
  15. * 使用javaAPI来操作hdfs
  16. */
  17. public class HDFSClient {
  18. /*
  19. * 在hdfs中创建文件夹
  20. */
  21. @Test
  22. public void testMkdir() throws URISyntaxException, IOException, InterruptedException {
  23. /*
  24. * util.Shell: Failed to locate the winutils binary in the hadoop binary path
  25. * 解决办法:
  26. * 1.下载winutils.exe 链接:http://public-repo-1.hortonworks.com/hdp-win-alpha/winutils.exe
  27. * 2.创建文件夹,比方说 D:\winutils\bin
  28. * 3.复制winutils.exe里面D:\winutils\bin
  29. * 4.将环境变量设置HADOOP_HOME为D:\winutils
  30. * 5.System.setProperty("hadoop.home.dir", "D://winutils");
  31. */
  32. System.setProperty("hadoop.home.dir", "D://winutils");
  33.  
  34. // 创建配置文件对象
  35. Configuration conf = new Configuration();
  36.  
  37. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  38.  
  39. fileSystem.mkdirs(new Path("/user/admin/404"));
  40.  
  41. fileSystem.close();
  42. }
  43.  
  44. /*
  45. * 下载文件
  46. */
  47. @Test
  48. public void testCopytoLocalFile() throws URISyntaxException, IOException, InterruptedException{
  49. System.setProperty("hadoop.home.dir", "D://winutils");
  50. // 创建配置文件对象
  51. Configuration conf = new Configuration();
  52.  
  53. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  54.  
  55. fileSystem.copyToLocalFile(
  56. false,
  57. new Path("/user/admin/403/hello_world2.txt"),
  58. new Path("d:\\copy_words.txt")
  59. );
  60.  
  61. fileSystem.close();
  62.  
  63. }
  64.  
  65. /**
  66. * 文件删除
  67. */
  68. @Test
  69. public void testDelete() throws URISyntaxException, IOException, InterruptedException {
  70. System.setProperty("hadoop.home.dir", "D://winutils");
  71. Configuration conf = new Configuration();
  72. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  73. fileSystem.delete(new Path("/user/admin/403/"), true);
  74. fileSystem.close();
  75. }
  76.  
  77. /**
  78. * 上传文件
  79. * JavaAPI在操作文件 上传时,如果文件已经存在于HDFS中,则先删除HDFS中的文件,再上传
  80. * 但是如果使用shell操作,则会提示,该文件已存在
  81. */
  82. @Test
  83. public void testCopyFromLocal() throws URISyntaxException, IOException, InterruptedException {
  84. System.setProperty("hadoop.home.dir", "D://winutils");
  85. Configuration conf = new Configuration();
  86. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  87. // fileSystem.copyFromLocalFile(new Path("d:\\copy_words.txt"), new Path("/"));
  88. fileSystem.copyFromLocalFile(new Path("d:" + File.separator + "copy_words.txt"), new Path("/"));
  89. fileSystem.close();
  90. }
  91.  
  92. /**
  93. * 重命名文件
  94. */
  95. @Test
  96. public void testReanme() throws URISyntaxException, IOException, InterruptedException {
  97. System.setProperty("hadoop.home.dir", "D://winutils");
  98. Configuration conf = new Configuration();
  99. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  100. fileSystem.rename(new Path("/user/admin/403/abc.txt")
  101. , new Path("/user/admin/403/aaa.txt"));
  102. fileSystem.close();
  103. }
  104.  
  105. /**
  106. * 展示目录列表
  107. */
  108. @Test
  109. public void testListFile() throws URISyntaxException, IOException, InterruptedException {
  110. System.setProperty("hadoop.home.dir", "D://winutils");
  111. Configuration conf = new Configuration();
  112. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  113. RemoteIterator<LocatedFileStatus> listFiles = fileSystem.listFiles(new Path("/"), true);
  114. while(listFiles.hasNext()){
  115. LocatedFileStatus fileStatus = listFiles.next();
  116. System.out.println("文件名称:" + fileStatus.getPath().getName());
  117. System.out.println("文件长度:" + fileStatus.getLen());
  118. System.out.println("文件权限:" + fileStatus.getPermission());
  119. System.out.println("文件所属组" + fileStatus.getGroup());
  120. //文件块信息
  121. BlockLocation[] blockLocations = fileStatus.getBlockLocations();
  122. for(BlockLocation blockLocation : blockLocations){
  123. String[] hosts = blockLocation.getHosts();
  124. for(String host : hosts){
  125. System.out.println(host);
  126. }
  127. }
  128. System.out.println("--------------这是一个毫无用处的分割线--------------------");
  129. }
  130. }
  131.  
  132. /**
  133. * 罗列目录或文件
  134. */
  135. @Test
  136. public void testListStatus() throws URISyntaxException, IOException, InterruptedException {
  137. System.setProperty("hadoop.home.dir", "D://winutils");
  138. Configuration conf = new Configuration();
  139. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  140. FileStatus[] listStatus = fileSystem.listStatus(new Path("/"));
  141. for(FileStatus status : listStatus){
  142. if(status.isFile()){
  143. System.out.println("文件:" + status.getPath().getName());
  144. }else{
  145. System.out.println("目录:" + status.getPath().getName());
  146. }
  147. }
  148. fileSystem.close();
  149. }
  150.  
  151. /**
  152. * 通过流的操作上传一个文件到HDFS
  153. */
  154. @Test
  155. public void putFileToHDFS() throws URISyntaxException, IOException, InterruptedException {
  156. System.setProperty("hadoop.home.dir", "D://winutils");
  157. Configuration conf = new Configuration();
  158. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  159. //读取当前操作系统本地的文件
  160. FileInputStream inputStream = new FileInputStream(new File("d:\\copy_words.txt"));
  161. //创建HDFS的输出流,用于将本地文件流中的数据拷贝到HDFS中
  162. FSDataOutputStream outputStream = fileSystem.create(new Path("/jinji_words.txt"));
  163. //流的对拷
  164. IOUtils.copyBytes(inputStream, outputStream, conf);
  165. fileSystem.close();
  166. }
  167.  
  168. /**
  169. * 通过流的方式,下载文件
  170. */
  171. @Test
  172. public void getFileFromHDFS() throws URISyntaxException, IOException, InterruptedException {
  173. System.setProperty("hadoop.home.dir", "D://winutils");
  174. Configuration conf = new Configuration();
  175. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  176.  
  177. FSDataInputStream inputStream = fileSystem.open(new Path("/hello_world.txt"));
  178. FileOutputStream outputStream = new FileOutputStream(new File("d:\\demo.txt"));
  179. IOUtils.copyBytes(inputStream, outputStream, conf);
  180. fileSystem.close();
  181. }
  182.  
  183. /**
  184. * 按照文件块进行下载
  185. * 可以在下载文件的过程中,设置每次要下载的字节数
  186. * 例如:我们下载一个文件的一个文件块 自己上传一个bin/hdfs dfs -put ~/softwares/installtions/hadoop-2.7.2.tar.gz /
  187. * 下载hadoop安装包(200多兆)的第一个文件块(128M)
  188. */
  189. @Test
  190. public void readFileSeek1() throws URISyntaxException, IOException, InterruptedException {
  191. System.setProperty("hadoop.home.dir", "D://winutils");
  192. Configuration conf = new Configuration();
  193. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  194.  
  195. FSDataInputStream inputStream = fileSystem.open(new Path("/hadoop-2.7.2.tar.gz"));
  196. FileOutputStream outputStream = new FileOutputStream(new File("d:\\hadoop-2.7.2.tar.gz.part1"));
  197. byte[] bytes = new byte[1024];//一次读取1KB的数据
  198.  
  199. for(int i = 0; i < 1024 * 128; i++){
  200. inputStream.read(bytes);
  201. outputStream.write(bytes);
  202. }
  203. IOUtils.closeStream(inputStream);
  204. IOUtils.closeStream(outputStream);
  205. }
  206.  
  207. /**
  208. * 下载第二个文件块
  209. */
  210. @Test
  211. public void readFileSeek2() throws URISyntaxException, IOException, InterruptedException {
  212. System.setProperty("hadoop.home.dir", "D://winutils");
  213. Configuration conf = new Configuration();
  214. FileSystem fileSystem = FileSystem.get(new URI("hdfs://192.168.1.213:8020"), conf, "admin");
  215.  
  216. FSDataInputStream inputStream = fileSystem.open(new Path("/hadoop-2.7.2.tar.gz"));
  217. FileOutputStream outputStream = new FileOutputStream(new File("d:\\hadoop-2.7.2.tar.gz.part2"));
  218.  
  219. inputStream.seek(128 * 1024 * 1024);
  220. // IOUtils.copyBytes(inputStream, outputStream, conf);
  221. //与上边的操作等价:
  222. byte[] bytes = new byte[1024];//一次读取1KB的数据
  223.  
  224. for(int i = 0; i < 77829046/1024; i++){
  225. inputStream.read(bytes);
  226. outputStream.write(bytes);
  227. }
  228. IOUtils.closeStream(inputStream);
  229. IOUtils.closeStream(outputStream);
  230.  
  231. fileSystem.close();
  232. }
  233.  
  234. }

  

注意:把linux下面/home/admin/modules/hadoop-2.7.2/etc/hadoop文件夹中的log4j.properties、core-site.xml、 hdfs-site.xml、mapred-site.xml、yarn-site.xml五个文件复制到wiondw下面项目中的:项目路径\src\main\resources 文件夹中

大数据(5) - HDFS中的常用API操作的更多相关文章

  1. 大数据技术之_11_HBase学习_02_HBase API 操作 + HBase 与 Hive 集成 + HBase 优化

    第6章 HBase API 操作6.1 环境准备6.2 HBase API6.2.1 判断表是否存在6.2.2 抽取获取 Configuration.Connection.Admin 对象的方法以及关 ...

  2. 大数据除了Hadoop还有哪些常用的工具?

    大数据除了Hadoop还有哪些常用的工具? 1.Hadoop大数据生态平台Hadoop 是一个能够对大量数据进行分布式处理的软件框架.但是 Hadoop 是以一种可靠.高效.可伸缩的方式进行处理的.H ...

  3. 漫谈ELK在大数据运维中的应用

    漫谈ELK在大数据运维中的应用 圈子里关于大数据.云计算相关文章和讨论是越来越多,愈演愈烈.行业内企业也争前恐后,群雄逐鹿.而在大数据时代的运维挑站问题也就日渐突出,任重而道远了.众所周知,大数据平台 ...

  4. jackson学习之三:常用API操作

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  5. Java+大数据开发——HDFS详解

    1. HDFS 介绍  • 什么是HDFS 首先,它是一个文件系统,用于存储文件,通过统一的命名空间--目录树来定位文件. 其次,它是分布式的,由很多服务器联合起来实现其功能,集群中的服务器有各自的角 ...

  6. 我要进大厂之大数据Hadoop HDFS知识点(1)

    01 我们一起学大数据 老刘今天开始了大数据Hadoop知识点的复习,Hadoop包含三个模块,这次先分享出Hadoop中的HDFS模块的基础知识点,也算是对今天复习的内容进行一次总结,希望能够给想学 ...

  7. hadoop学习;大数据集在HDFS中存为单个文件;安装linux下eclipse出错解决;查看.class文件插件

    sudo apt-get install eclipse 安装后打开eclipse,提示出错 An error has occurred. See the log file /home/pengeor ...

  8. 老李分享:大数据测试之HDFS文件系统

    poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478,咨询电话010-845052 ...

  9. 大数据学习——hdfs客户端流式操作代码的实现

    package cn.itcast.bigdata.hdfs.diceng; import org.apache.hadoop.conf.Configuration; import org.apach ...

随机推荐

  1. React Native Navigator组件回调

    在push的时候定义回调函数: this.props.navigator.push({ component: nextVC, title: titleName, passProps: { //回调 g ...

  2. HTML-DEV-ToolLink(常用的在线字符串编解码、代码压缩、美化、JSON格式化、正则表达式、时间转换工具、二维码生成与解码等工具,支持在线搜索和Chrome插件。)

    HTML-DEV-ToolLink:https://github.com/easonjim/HTML-DEV-ToolLink 常用的在线字符串编解码.代码压缩.美化.JSON格式化.正则表达式.时间 ...

  3. 精通JavaScript攻击框架:AttackAPI

    多年来客户端安全一直未引起人们的足够重视,但是如今情况发生了急剧转变,客户端安全已经成为信息安全领域的焦点之一.Web恶意软件.AJAX蠕虫.浏览历史暴破.登录检测.傀儡控制技术网络端口扫描以及浏览器 ...

  4. 表格中的IE BUG

    在表格应用了跨列单元格后,在IE6/7下当跨列单元格中的元素长度超过其跨列单元格中第一个单元格的宽度时会产生换行,如下所示: 解决方法: 1. 设置 table 的 'table-layout' 特性 ...

  5. 【面试问题】—— 2019.3月前端面试之JS原理&CSS基础&Vue框架

    前言:三月中旬面试了两家公司,一家小型公司只有面试,另一家稍大型公司笔试之后一面定夺.笔试部分属于基础类型,网上的复习资料都有. 面试时两位面试官都有考到一些实际工作中会用到,但我还没接触过的知识点. ...

  6. 用C++实现文件压缩(1 哈弗曼编码)

    今天下午想把文件压缩写一下,因为我觉得这个还是比较锻炼技术的,对数据结构的要求应该比较高,权当练习了吧. 我采用的压缩方式是Huffman编码,不过比较囧的是,我拼写拼错了,我拼的是haffman,在 ...

  7. 如何将微信小程序页面内容充满整个屏幕

    修改该页面的wxss文件 /* pages/weather/weather.wxss */ .weather{ position: fixed; height: 100%; width: 100%; ...

  8. MySQL错误Another MySQL daemon already running with the same unix socket.v

    etc/init.d/mysqld start 结果显示 Another MySQL daemon already running with the same unix socket.显示另一个MyS ...

  9. Spring Cloud简单入门教程

    原文地址:http://www.cnblogs.com/skyblog/p/5127690.html 按照官方的话说:Spring Cloud 为开发者提供了在分布式系统(如配置管理.服务发现.断路器 ...

  10. WORD文档书签管理

    最近在浏览一个word超长文档,在文档中有几处要点用颜色做了标记,但是在下次查找的时候无法定位,还得一页页去翻,而且无法通过目录概览的形式查看总共做了多少处标记 于是想到了书签 原本以为在视图中能够设 ...