我在网络中连接了两个系统。一个是hdfs运行。我想创建一个文件并从另一台机器写入数据。
package myorg;
import java.io.*;
import java.util.*;
import java.net.*;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class Write1{
public static void main (String [] args) throws Exception{
try{
System.out.println("Starting...");
Path pt=new Path("hdfs://10.236.173.95:8020/user/jfor/out/gwmdfd");
FileSystem fs = FileSystem.get(new Configuration());
BufferedWriter br=new BufferedWriter(new OutputStreamWriter(fs.create(pt,true)));
// TO append data to a file, use fs.append(Path f)
String line;
line="Disha Dishu Daasha dfasdasdawqeqwe";
System.out.println(line);
br.write(line);
br.close();
}catch(Exception e){
System.out.println("File not found");
}
}
}
我是用
javac -classpath hadoop-0.20.1-dev-core.jar -d Write1/ Write1.java
使用创建了一个jar
jar -cvf Write1.jar -C Write1/ .
run命令
hadoop jar Write1.jar myorg.Write1
如果我运行这个,我会
starting...
File not found
原因是什么?如果我在hadoop机器上运行这个程序,它可以正常工作[我用localhost替换了ip]。
bufferedwriter行出错。上面写着“找不到文件”。这是什么意思?我曾经 fs.creat
. 如果它不存在,它就应该创建。不是吗?
java.lang.IllegalArgumentException: Wrong FS: hdfs://10.72.40.68:8020/user/jfor/..... expected localhost:8020
So i modified the following line
FileSystem fs = FileSystem.get(new URI("hdfs://<ip>:8020"),new Configuration());
It says Connection refused. What could be the reason
暂无答案!
目前还没有任何答案,快来回答吧!