In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about the operation of java to hdfs. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Package hdfs;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.net.URI;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 / * * java's operation on hdfs * @ author forest * * / public class App2 {public static final String HDFS_PATH = "hdfs://hadoop:9000"; public static final String DRI_PATH = "/ d1000"; public static final String FILE_PATH = "/ d1000/f1000"; public static void main (String [] args) throws Exception {FileSystem fileSystem = FileSystem.get (new URI (HDFS_PATH), new Configuration ()); / / create a folder mkDri (fileSystem) / / upload file uploadDate (fileSystem); / / download file downloadFile (fileSystem); / / delete file deleteFile (fileSystem);} public static void deleteFile (FileSystem fileSystem) throws IOException {fileSystem.delete (new Path (FILE_PATH), true);} / download file public static void downloadFile (FileSystem fileSystem) throws IOException {FSDataInputStream in = fileSystem.open (new Path (FILE_PATH)); FileOutputStream out = new FileOutputStream (new File ("D:/copy.txt")) / / IOUtils.copyBytes (in, System.out, 2048, true); download to the console IOUtils.copyBytes (in,out, 2048, true);} / upload the file public static void uploadDate (FileSystem fileSystem) throws IOException, FileNotFoundException {FSDataOutputStream out = fileSystem.create (new Path (FILE_PATH)); FileInputStream in = new FileInputStream ("D:/hadoop installation .txt"); IOUtils.copyBytes (in,out, 1024 real) } / / create a directory public static void mkDri (FileSystem fileSystem) throws IOException {fileSystem.mkdirs (new Path (DRI_PATH));}} this is the operation of java to hdfs shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.