下面是代码片段,目标是在hadoop/tmp目录中写入一些文件,但得到nullpointerexception(因为hadoop不能创建目录或在/tmp目录中写入),我使用的是单用户,因此没有权限问题,并将chmod 777赋予/tmp目录。
public static class BigBWAMap extends
Mapper<Object,Text,IntWritable,Text>
File fout;
FileOutputStream fos;
BufferedWriter bw;
String tmpFileString = "";
String[] values1;
String[] values2;
String tmpDir;
//setup method
@Override
protected void setup(Context context) {
Configuration conf = context.getConfiguration();
tmpDir = conf.get("hadoop.tmp.dir","/tmp/");
if(tmpDir == null || tmpDir.isEmpty()) {
tmpDir = "/tmp/";
}
tmpFileString = tmpDir+"/HadoopTMPFile-"1"-"+213"; // directory where to write: /tmp/HadoopTMPFile-1-213
fout = new File(tmpFileString);
try {
fos = new FileOutputStream(fout);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bw = new BufferedWriter(new OutputStreamWriter(fos));
}
}
获取bw处的nullpointerexception=new bufferedwriter(new outputstreamwriter(fos));由于as/tmp/hadooptmpfile-1-213不可写。即使我试着写给/tmp也只能得到相同的npe。
暂无答案!
目前还没有任何答案,快来回答吧!