Get the App
SLTechnology News&Howtos  ›  Servers  › 

What does java do to hdfs?

Shulou Source: shulou.com Published: 2022-06-01 00:27:08 09月11日 Update

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.

Tags: Documents content analysis professional small and medium rich in content that is console folder article more directory knowledge article industry perspective information information channel channel control Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Microsoft MySQL Linux MariaDB