In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you how to operate HDFS in Java, the content is very detailed, interested friends can refer to, hope to be helpful to you.
Here is the code:
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 {/ * * create method shortcuts using FileSystem * * eclipse: alt+shift+M * eclipse create local variable shortcuts 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 ()); / / create a folder CreatePackage (fileSystem); / / upload files / / UploadFile (fileSystem) / / download file / / Download (fileSystem); / / delete file / / 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) }} this is the end of sharing about how to operate HDFS in Java. I hope the above content can help you to some extent and learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.