0% found this document useful (0 votes)
5 views1 page

A

The document contains Java code that interacts with Hadoop's HDFS to check for the existence of a file named 'test'. It sets up the necessary configuration for connecting to HDFS and uses the FileSystem class to determine if the file exists, printing the result to the console. Exception handling is included to manage any errors that may occur during execution.

Uploaded by

uuuuuvp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

A

The document contains Java code that interacts with Hadoop's HDFS to check for the existence of a file named 'test'. It sets up the necessary configuration for connecting to HDFS and uses the FileSystem class to determine if the file exists, printing the result to the console. Exception handling is included to manage any errors that may occur during execution.

Uploaded by

uuuuuvp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//import org.apache.hadoop.conf.

Configuration;
//import org.apache.hadoop.fs.FileSystem;
//import org.apache.hadoop.fs.FSDataOutputStream;
//import org.apache.hadoop.fs.Path;
//
//public class Chapter3 {
// public static void main(String[] args){
// try {
// Configuration conf = new Configuration();
// conf.set("fs.defaultFS","hdfs://localhost:9000");
//
conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem");
// FileSystem fs = FileSystem.get(conf);
// byte[] buff="Hello world".getBytes();
// String filename="test";
// FSDataOutputStream os = fs.create(new Path(filename));
// os.write(buff,0,buff.length);
// System.out.println("create:"+ filename);
// os.close();
// fs.close();
//
// } catch(Exception e){
// e.printStackTrace();
// }
// }
//}

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class Chapter3 {


public static void main(String[] args){
try {
String filename="test";
Configuration conf = new Configuration();
conf.set("fs.defaultFS","hdfs://localhost:9000");

conf.set("fs.hdfs.impl","org.apache.hadoop.hdfs.DistributedFileSystem");
FileSystem fs = FileSystem.get(conf);
if(fs.exists(new Path(filename))) {
System.out.println("file does exit");
}else {
System.out.println("file not exits");
}
fs.close();
} catch(Exception e){
e.printStackTrace();
}
}
}

You might also like