您现在的位置是:挑肥拣瘦网 > 热点
HDFS中的Java和Python API接口连接
挑肥拣瘦网2026-11-14【热点】{固定数字1}人已围观
简介谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】
上次介绍了HDFS的简单操作,今天进入HDFS中的Java和Python的API操作,后面可能介绍Scala的相关的。
在讲Java API之前介绍一下使用的IDE——IntelliJ IDEA ,我本人使用的是2020.3 x64的社区版本。
Java API
创建maven工程,关于Maven的配置,在IDEA中,Maven下载源必须配置成阿里云。
在对应的D:apache-maven-3.8.1-binapache-maven-3.8.1confsettings.xml需要设置阿里云的下载源。
下面创建maven工程,添加常见的依赖
添加hadoop-client依赖,版本最好和hadoop指定的一致,并添加junit单元测试依赖。
&nbHDsp; org.apache.hadoop hadoop-common 3.1.4 org.apache.hadoop hadoop-hdfs FS 3.1.4 org.apache.hadoop hadoop-client 3.1.4 junit junit  中的; 4.11 HDFS文件上传
在这里编写测试类即可,新建一个java文件:main.java
这里的FileSyste一开始是本地的文件系统,需要初始化为HDFS的文件系统
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.junit.Test; import java.net.URI; public class main&Janbsp;{ @Test public void testPut() throws Exception { // 获取FileSystem类的方法有很多种,这里只写一种(比较常用的是使URI) Configuration configuration = new&nvabsp;Configuration(); // user是Hadoop集群的账号,连接端口默认9000 FileSystem fileSystem = FileSystem.get( new URI("hdfs://192.168.147.128:9000"), 和P configuration, "hadoop"); // 将f:/stopword.txt 上传到 /user/stopword.txt yt fileSystem.copyFromLocalFile( new Path("f:/stopword.txt"), new Path("/user/stopword.txt")); fileSystem.close(); } }
在对应的HDFS中,就会看见我刚刚上传的机器学习相关的停用词。
HhoDFS文件下载
由于每次都需要初始化FileSystem,比较懒的我直接使用@Before每次加载。
HDFS文件下载的API接口是copyToLocalFile,具体代码如下。
@Test public void testDownload() throws Exception { Configuration configuration = new Configuration(); FileSystem fileSystem = FileSystem.get( &nn bsp; new URI("hdfs://192.168.147.128:9000"), configuration, "hadoop"); fileSystem.copyToLocalFile( &APnbsp; false, new Path("/user/stopword.txt"), new Path("stop.txt"), true); I接 fileSystem.close(); System.out.println("over"); } Python API
下面主要介绍hdfs,参考:https://hdfscli.readthedocs.io/
我们通过命令pip install hdfs安装hdfs库,在使用hdfs前,使用命令hadoop fs -chmod -R 777 / 对当前目录及目录下所有的文件赋予可读可写可执行权限。
>>> from hdfs.client import Client >>> #2.X版本port 使用50070 3.x版口连本port 使用9870 >>> client = Client('http://192.168.147.128:9870') >>> client.list('/') #查看hdfs /下的目录 ['hadoop-3.1.4.tar.gz'] >>> client.makedirs('/test') >>> client.list('/') ['hadoop-3.1.4.tar.gz', 'test'] >>> clHDient.delete("/test") True >>> client.download('/hadoop-3.1.4.tar.gz','C:\Users\YIUYE\Desktop') 'C:\Users\YIUYE\Desktop\hadoop-3.1.4.tar.gz' >>> client.upload('/','C:\Users\YIUYE\Desktop\demo.txt') >>> client.list('/') '/demo.txt' >>> client.list('/') ['demo.txt', 'hadoop-3FS.1.4.tar.gz'] >>> # 上传demo.txt 内容:Hello hdfs >>> with client.read("/demo.txt") as reader: ... print(reader.read()) b'Hello hdfs '
相对于Java API,Python API连接实在简单。
很赞哦!(517026)
热门文章
站长推荐
友情链接
- 标签: 康师傅
- https://www.libros.unam.mx/catalogsearch/result/?cat=37&dir=asc&format=20&lit=20&manufacturer=3230&mode=list&order=year_edition&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,dDc
- https://yscc1986.net/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】vZm
- https://www.polliwogs.com/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,MXq
- https://www.teacherspayteachers.com/Browse/Price-Range/Free/Search:Western International University Physics degree=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Fg5
- https://www.vocabulary.com/dictionary/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ZOE
- https://www.silentiumpc.com/en/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,BhK
- https://www.temu.com/search_result.html?search_key=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】HgF
- https://www.televes.com/es/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,jgB
- https://search.danawa.com/dsearch.php?query=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】WLn
- https://nicolazzi.it/en/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,mU4
- https://www.writingforward.com/?action=SEARCH&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,E9H
- https://www.springfieldlibrary.org/library/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,EIV
- https://www.duksung.ac.kr/search/front/Search.jsp?qt=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】Jo0
- https://www.ucycle.com/search/=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Lv2
- https://www.synonyms.com/antonyms/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Kjq
- https://www.voices.com/talents/search?keywords=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ogS
- https://www.niaogebiji.com/pc/article/search?keyword=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Jns
- https://www.mintos.org/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,C5K
- https://www.tycoonstory.com/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,4IW
- https://hsmoa.com/search?query=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】RwC
- https://www.abbreviations.com/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】gEW
- https://www.kores.com/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,yEb
- https://wwwcp.umes.edu/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,lVk
- https://www.samen-maier.at/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,I4K
- https://www.signingsavvy.com/sentence/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,wMX
- https://www.youtube.com/hashtag/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,uGF
- https://www.livehindustan.com/tags/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,zJZ
- https://www.roblox.com/discover/?cat=107&Keyword=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ecn
- https://www.tahiti-infos.com/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,p98
- https://www.sbaad.no/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Hkm
- https://www.pmindia.gov.in/en/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ICU
- https://www.therapeuticassociates.com/?cat=5&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Lku
- https://www.madebyoranges.com/nl/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,ivC
- https://www.remit.co.jp/en/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,TgO
- https://www.roberthalf.com/us/en/jobs/all/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】2ER
- https://www.pearson.com/en-us/search.html?aq=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,9l2
- https://www.mi.com/search?keyword=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,G7w
- https://www.londontheatredirect.com/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,y9C
- https://www.tarleton.edu/?s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,FhX
- https://zhidao.baidu.com/index/?action=QUERY&word=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,r8T
- https://www.nextavenue.org/?action=QUERY&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,szG
- https://www.abbreviations.com/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】BW7
- https://www.teamlab.art/pt/?submit=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Drr
- https://www.kaliastyle.com/catalogsearch/result/?q=GOOGLE谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,hlj
- https://www.totolink.vn/search/谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,XGi
- https://www.symatoys.com/search.html?ID=UyMD6aO58bPrJvQAB1I0N69KzJBZeNPC&keyword=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,g7c
- https://www.ntv.co.jp/3min/search/?action=QUERY&q=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,t9I
- https://www.riohondo.edu/?action=QUERY&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,Ffd
- https://www.udc.co.uk/index.php?route=product/search&sort=p.price&order=DESC&tag=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,wgO
- https://www.miamiopenmri.com/?action=CHECK&s=谷歌霸屏24小时见效-实现思路与效果衡量【tg:seogoogle987】,pHy







