這篇文章給大家介紹Java中怎么對HDFS進(jìn)行操作,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

在藍(lán)山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作按需搭建網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),成都全網(wǎng)營銷推廣,外貿(mào)網(wǎng)站制作,藍(lán)山網(wǎng)站建設(shè)費(fèi)用合理。
以下是代碼:
package hdfs;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
public class App2 {
/**
*
* 使用 FileSystem
*
* eclipse 創(chuàng)建方法快捷鍵:alt+shift+M
* eclipse 創(chuàng)建局部變量快捷鍵 alt+shift+L
*
* */
public static final String HDFS_PATH = "hdfs://192.168.9.204:9000";
private static final String DIR_PATH = "/user/yinkaipeng";
private static final String FILE_PATH = "/test";
public static void main(String[] args) throws Exception, URISyntaxException {
FileSystem fileSystem = FileSystem.get(new URI(HDFS_PATH),new Configuration());
// 創(chuàng)建文件夾
CreatePackage(fileSystem);
// 上傳文件
//UploadFile(fileSystem);
// 下載文件
// Download(fileSystem);
//刪除文件
//deleteFile(fileSystem);
}
private static void deleteFile(FileSystem fileSystem) throws IOException {
fileSystem.delete(new Path(FILE_PATH), true);
System.out .println("OK!");
}
private static void UploadFile(FileSystem fileSystem) throws IOException,
FileNotFoundException {
final FSDataOutputStream out = fileSystem.create(new Path(FILE_PATH));
final FileInputStream in = new FileInputStream("c:/log.txt");
IOUtils.copyBytes(in, out, 1024, true);
}
private static void CreatePackage(FileSystem fileSystem) throws IOException {
fileSystem.mkdirs(new Path(DIR_PATH));
}
private static void Download(FileSystem fileSystem) throws IOException {
final FSDataInputStream in2 = fileSystem.open(new Path(FILE_PATH));
IOUtils.copyBytes(in2, System.out, 1024, true);
}
}關(guān)于Java中怎么對HDFS進(jìn)行操作就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
文章名稱:Java中怎么對HDFS進(jìn)行操作
轉(zhuǎn)載來源:http://chinadenli.net/article18/ipghgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站導(dǎo)航、網(wǎng)站策劃、虛擬主機(jī)、商城網(wǎng)站、面包屑導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)