hdfs api

HDFS的API操作 HDFS的API客户端操作,基本的增删改查、以及对于文件的上传下载、本地与服务器集群的交互等 阅读详情
public static FileSystem getHDFS() {
<span style="white-space:pre">		</span>FileSystem fs =null;
<span style="white-space:pre">		</span>
<span style="white-space:pre">		</span>Configuration conf = new Configuration();
<span style="white-space:pre">		</span>try {
<span style="white-space:pre">			</span>fs= FileSystem.get(conf);
<span style="white-space:pre">		</span>} catch (IOException e) {
<span style="white-space:pre">			</span>e.printStackTrace();
<span style="white-space:pre">		</span>}
<span style="white-space:pre">		</span>return fs;
<span style="white-space:pre">	</span>}
</pre><pre name="code" class="java">
</pre><pre name="code" class="java">
</pre><pre name="code" class="java">
</pre><pre name="code" class="java">/**
	 * 上传本地文件
	 */
	@Test
	public void testUpload() {
		try {
			FileSystem hdfs = HDFSUtils.getHDFS();
			hdfs.copyFromLocalFile(localPath, descPath);
			FileStatus[] fileStatus = hdfs.listStatus(descPath);

			for (FileStatus status : fileStatus) {
				Path path = status.getPath();
				System.out.println(path.getName());
			}
			hdfs.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 创建新文件
	 * 
	 * @throws Exception
	 */
	@Test
	public void testCreate() throws Exception {
		byte[] buff = "hello world!".getBytes();

		FileSystem hdfs = HDFSUtils.getHDFS();
		Path dst = new Path(descPath + "/hello4.txt");
		FSDataOutputStream outputStream = null;
		try {
			outputStream = hdfs.create(dst);
			outputStream.write(buff, 0, buff.length);
		} catch (Exception e) {
			e.printStackTrace();

		} finally {
			if (outputStream != null) {
				outputStream.close();
			}
		}

		FileStatus files[] = hdfs.listStatus(dst);
		for (FileStatus file : files) {
			System.out.println(file.getPath());
		}
	}

	/**
	 *  遍历HDFS上的文件和目录
	 */

	@Test
	public void testList() {
		FileSystem hdfs = HDFSUtils.getHDFS();
		Path path = new Path("/");
		try {
			FileStatus[] fileStatus = hdfs.listStatus(path);
			for (FileStatus status : fileStatus) {
				Path p = status.getPath();
				String str = status.isDir() ? "目录" : "文件";
				System.out.println(str + ":" + p);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 文件重命名
	 */
	@Test
	public void testRename() {
		Path oldPath = new Path("/home/hell.txt");
		Path newPath = new Path("/home/new.log");
		FileSystem hdfs = HDFSUtils.getHDFS();
		try {
			boolean falg = hdfs.rename(oldPath, newPath);
			hdfs.close();
			System.out.println(falg);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 读取文件的内容
	 */
	@Test
	public void readFile() {
		Path path = new Path("/home/big1.pdf");
		FileSystem hdfs = HDFSUtils.getHDFS();
		try {
			FSDataInputStream in = hdfs.open(path);
			IOUtils.copyBytes(in, System.out, 4096, false); // 复制到标准输出流

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * 删除文件
	 */
	@Test
	public void delete() {
		FileSystem hdfs = HDFSUtils.getHDFS();
		Path path = new Path("/home/new.log");
		// 删除目录 不管是否为空目录
		// boolean falg=hdfs.delete(new Path("/home/test"));
		// 删除目录 不为空目录
		// boolean b=hdfs.delete(new Path("/home/test"),false);
		// 删除目录 不管是否为空目录
		// boolean falg=hdfs.delete(new Path("/home/aa"),true);

		try {
			boolean falg = hdfs.deleteOnExit(path);
			System.out.println(falg);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}


url


public class HDFSUrl {
	static {
		URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
	}

	@Test
	public void readFile() {

		try {
			URL url = new URL("hdfs://192.168.102.130:9000/home/hello.txt");
			InputStream in = url.openStream();
			IOUtils.copyBytes(in, System.out, 1024);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}



Android 面试题 Handler篇 1.Handler的实现原理。 阅读详情

相关推荐

基于奥比中光Orbbec Astra Pro与ROS实现实时3D环境建模:orb_slam2实战指南

本文提供了一份详细的实战指南,介绍如何使用奥比中光Orbbec Astra Pro深度摄像头与ROS系统,部署并运行ORB-SLAM2算法,实现实时3D环境建模与定位。内容涵盖从驱动安装、环境配置、算法编译到摄像头标定与性能调优的全流程,旨在帮助开发者快速搭建一套高性价比的视觉SLAM系统。

weixin_29054399的博客 334

HDFS多线程追加写数据踩坑

上一个同事使用strom框架,在Bolt的prepare中执行定时任务,将缓存数据利用HDFS原生API定时写入HDFS。 最近将缓存系统改成了Redis,改写代码过程中,发现多线程调用HDFS的API进行追加写的代码各种报错。 下面将踩坑总结如下: Hadoop的官方说明书明确指明,HDFS不可以多线程写,可以多线程读。 通过测试,使用redis公平锁的方式,可以将数据多线程写入HDFS中。 具...

白昼的晚上 5731

自抗扰(ADRC)控制原理及控制器设计

自抗扰控制原理以及控制器设计

weixin_43487974的博客 3万+

【错误处理】HDFS出现的问题:File /hdfsapi/test/a.txt could only be replicated to 0 nodes instead of

最近在阿里云上进行伪分布式Hadoop开发,在本地windows的java程序对HDFS进行访问时,出现了如下问题: File /hdfsapi/test/a.txt could only be replicated to 0 nodes instead of minReplication (=1) 经过多方查询,了解到问题的原因:客户端操作hdfs时候...

victorzzzz的专栏 2144

从零构建:毫米波雷达生命信号检测系统的Matlab仿真全流程解析

本文详细解析了毫米波雷达生命信号检测系统的Matlab仿真全流程,涵盖原理、信号处理链路设计及算法优化策略。通过FMCW雷达技术,实现非接触式呼吸心跳信号检测,结合Matlab代码示例展示距离FFT、相位提取与信号分离等关键步骤,为医疗监护和智能家居应用提供实用指南。

weixin_29303701的博客 355

知识存储之Apache Jena

知识图谱的存储可以分为基于表结构的存储和基于图结构的存储。1️⃣基于表结构的存储基于表结构的存储利用二维的数据表对知识图谱中的数据进行存储。根据不同的设计原则,知识图谱可以具有不同的表结构:💨知识图谱实质上是一个个的三元组,一种简单直接的存储方式是设计一张三元组表用于存储所有三元组,有不少比较成熟的产品利用该形式存储知识图谱,包括Jena、Oracle、Virtuoso等。💨为每种类型构建一张表,同一类型的实例存放在相同的表中。

Puzzle的博客 6065

深入理解HDFS 的架构和原理

(一) HDFS主要是用于做什么的?       HDFS(Hadoop Distributed File System)是Hadoop项目的核心子项目,是分布式计算中数据存储管理的基础,是基于流数据模式访问和处理超大文件的需求而开发的,可以运行于廉价的商用服务器上。它所具有的高容错、高可靠性、高可扩展性、高获得性、高吞吐率等特征为海量数据提供了不怕故障的存储,为超大数据集(

JimGray的博客 8490

hdfs文件上传与文件下载

1.文件上传 2.文件下载

jump_tigris的博客 1494

基于STM32、HAL库的IP2736U_EF快充协议芯片简介及驱动程序设计

@param connected: 连接状态指针 (1=已连接, 0=未连接)= 0x2736) // 检查厂商ID。* @param hip: IP2736U句柄指针。* @param hip: IP2736U句柄指针。* @param hip: IP2736U句柄指针。* @param hip: IP2736U句柄指针。* @param hip: IP2736U句柄指针。* @param hip: IP2736U句柄指针。* @param hip: IP2736U句柄指针。

corlin6688的博客 430

【华为OD技术面试真题 - 技术面】- 测试面试题(1)

专栏:华为OD面试真题精选 目录: 2024华为OD面试手撕代码真题目录以及八股文真题目录黑盒测试:白盒测试:基本功能验证:边界条件测试:空白输入测试:特殊字符和格式测试:响应时间测试:压力测试:针对在不同系统和设备上测试聊天窗口功能,以及网络正常的前置条件,我们可以增加以下测试用例:系统和设备:PC端测试:移动端测试:功能验证:前置条件:网络性能影响测试:Postman:SoapUI:JMeter:Rest-Assured:Tricentis Tosca:ReadyAPI:CI/CD工具集成:测试管理工

算法大师! 3690

Java API操作HDFS

1、基于HDFS 的Java API实现如下功能:(1)本地文件上传到HDFS;(2)从HDFS中下载文件到本地系统;(3)HDFS中目录的创建、删除、重命名;(4)查看目录中所有文件的详细信息。在win系统下不配置hadoop环境,直接运行代码会报错,显示缺少winutils.exe 和 hadoop.dll 两个文件1-将hadoop-win-2.7.7文件夹拷贝到一个没有中文的路径中; 2-在windows系统,配置hadoop的环境变量: HADOOP_HOME,并将%HADOOP_HOME%\bi

一指流沙的博客 6762

【HALCON工业视觉应用探索】10. C#+Halcon 3D视觉实战:点云处理与三维测量工业指南(附完整代码与实操案例)

摘要:本文聚焦C#+Halcon在3D视觉领域的工业应用,从新手友好的“基础3D检测系统”切入,逐步深入“汽车铸件三维测量”等工业级场景。内容涵盖核心概念(点云数据结构、3D采集原理、坐标系统)、完整技术流程(数据采集→预处理→特征提取→三维测量→结果可视化)、工业级代码实现(多视角点云融合、微缺陷检测、高精度尺寸测量),以及现场落地关键技巧(硬件选型、标定流程、抗干扰优化)。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 2004

【Hadoop】HDFS API 操作大全

为了提供对不同数据访问的一致接口,Hadoop借鉴了Linux虚拟文件系统的概念,为此Hadopo提供了一个抽象的文件系统模型FileSystem,HDFS 是其中的一个实现。 FileSystem是Hadoop中所有文件系统的抽象父类,它定义了文件系统所具有的基本特征和基本操作。

康师傅没有眼泪 4168

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

HDFS Java API 操作

java API 操作hdfs

m0_72168501的博客 4314

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

常用HDFS的API操作

标题

Master chy 6494

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

HDFS API操作

HDFS客户端API基本操作

江韵的博客 2805

通过HDFS API 进行HDFS操作

通过HDFS API进行HDFS操作

weixin_51568626的博客 1840

HDFS调用API

HDFS调用API:用一台机器管理所有集群shell 脚本 是在集群里面操作 HDFSIDEA 是在另一台机器PC上操作整个集群。

2301_80169572的博客 1235

HDFS的JAVA API操作

HDFS JAVA API操作详解

shield911的博客 3368

HDFS API

第一步:安装插件 找到eclipse操作hadoop的插件,eclipse-xxxx-hadoop-plugin.jar ,把它放到eclipse的安装路径的plugin文件夹中,然后重启eclipse。 第二步:配置hadoop环境变量 一、安装JDK 二、配置Java环境变量 测试: 打开命令行cmd java -version 可以得到java版本信息即可。具体不展开了。 三、下载Hadoop 1、下载路径:http://hadoop.apache.org/releases....

sunshunli的博客 366

编写HDFS的API

在IDEA中创建一个Maven项目 用来编写HDFS的API 导入依赖 <dependencies> <!-- https://mvnrepository.com/artifact/junit/junit --> <dependency> <groupId>junit</groupId&...

XXuan_的博客 278

使用IDEA工具通过Java API 访问HDFS

使用IDEA工具通过Java API 访问HDFS

Python_XTyyds的博客 3395

HDFS的Java API操作

通过Java代码操作HDFS集群 目录 引言 Idea连接HDFS 第一步:引入HDFS依赖 第一种引入方式(jar包) 第二种引入方式(使用maven引用) 引入项目依赖的时候: maven项目的几个核心的生命周期: 第二步:idea操作 配置HDFS的访问路径 单元测试 HDFS的JavaAPI基本操作 Maven依赖准备 hdfs文件系统的API使用 操作HDFS: 连接HDFS文件系统------是必备操作(见二、idea连接HDFS) 对HDFS进行操作 递.

zyd_994264926326的博客 1683

HDFS编程(基于Python语言调用HDFS API)

在删除目录时,如果改目录为空目录,即目录下没有文件会报<hdfs.util.HdfsError: `/usr is non empty': Directory is not empty>错误。如果我们使用python自带方法help()查看delete()方法我们会发现delete方法拥有三个参数。下载文件是指从HDFS文件系统中选择文件,下载到本地,使用的方法是download。查看文件内容使用read方法,使用方法与python自带read方法类似。删除文件与删除目录类似,使用delete方法。

2401_84950008的博客 1596
上一篇: 运行hadoop报错
下一篇: wordcount
wangkjs
博客等级 码龄11年 3粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值