0
hello每一個我工作在hadoop和我配置2節點hadoop羣集。我必須使用java代碼在hadoop文件系統中創建目錄,但每次運行此代碼時,我都會遇到一些異常。調用hadoop文件系統時在java代碼中的異常
我的Java代碼
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class Hadoopjava {
public static void main(String ar[]) throws IOException
{
Configuration conf = new Configuration();
/*conf.addResource(new Path("core-site.xml"));
conf.addResource(new Path("hdfs-site.xml"));*/
conf.set("fs.default.name", "hdfs://master:54310");
String dirName = "dd";
//values of hosthdfs:port can be found in the core-site.xml in the fs.default.name
FileSystem fileSystem = FileSystem.get(conf);
Path path = new Path("/user/hduser/dd/gg");
fileSystem.mkdirs(path) ;
// System.out.println(data);
/*Path path = new Path("/user/hduser/dd");
if (fileSystem.exists(path)) {
System.out.println("Dir " + dirName + " already exists");
return;
}
// Create directories
fileSystem.mkdirs(path);*/
fileSystem.close();
}
}
異常在我的代碼
Exception in thread "main" java.io.IOException: Call to master/192.168.0.128:54310 failed on local exception: java.io.EOFException
at org.apache.hadoop.ipc.Client.wrapException(Client.java:775)
at org.apache.hadoop.ipc.Client.call(Client.java:743)
at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:220)
at sun.proxy.$Proxy0.getProtocolVersion(Unknown Source)
at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:359)
at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:106)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:207)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:170)
at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:82)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1378)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:66)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1390)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:196)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:95)
at com.widevision.hadoop.Hadoopjava.main(Hadoopjava.java:26)
Caused by: java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:392)
at org.apache.hadoop.ipc.Client$Connection.receiveResponse(Client.java:501)
at org.apache.hadoop.ipc.Client$Connection.run(Client.java:446)
我使用的Eclipse IDE的Java代碼。
我的代碼有什麼問題?
非常感謝您的回答我的問題先生我先生在集羣中的所有系統上運行相同的版本。 – Simmant
您使用的是哪個版本的Hadoop?該代碼是否位於遠程機器上? – Tariq
先生,我正在使用hadoop 1.2.0先生,這個代碼是在同一臺機器先生。 – Simmant