Answers for "hdfs write file java"

2

java write on hdfs

Configuration configuration = new Configuration();
configuration.set("fs.defaultFS", "hdfs://localhost:9000");
FileSystem fileSystem = FileSystem.get(configuration);
//Create a path
String fileName = "my_text.txt";
// using "/" in the start of the path will ensure to get the exact path that I want
Path hdfsWritePath = new Path("/my/dirr/" + fileName);
FSDataOutputStream fsDataOutputStream = fileSystem.create(hdfsWritePath,true);
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(fsDataOutputStream,StandardCharsets.UTF_8));
/** Output the results to the HDFS **/
bufferedWriter.write("Hello from java");
bufferedWriter.newLine();
bufferedWriter.close();
fileSystem.close();
Posted by: Guest on June-09-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language