我在主類中使用了下面提到的分佈式緩存代碼。在Hadoop中使用DistributedCache時發生異常
job.addCacheFile(new URI(args[2]));
下面提到的代碼是在reduce類中。
@Override
protected void setup(Reducer<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
super.setup(context);
URI[] paths = context.getCacheFiles();
if (paths.length > 0) {
loadDeliveryStatusCodes(paths[0].toString());
}
}
private void loadDeliveryStatusCodes(String file) {
String strRead;
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader("./some"));
while ((strRead = reader.readLine()) != null) {
String splitarray[] = strRead.split(",");
deliveryCodesMap.put(splitarray[0].trim(), splitarray[1].trim());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
我得到下面提到的異常。
@@@@@@@@/user/DeliveryStatusCodes.txt 1
java.io.FileNotFoundException: ./some (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at java.io.FileReader.<init>(FileReader.java:58)
at com.hadoop.intellipaat.UserSMSDeliveryJob$USERNameSMSStatusCodeMapper.loadDeliveryStatusCodes(UserSMSDeliveryJob.java:95)
你的幫助將拯救我的一天。 謝謝。
什麼是'ARGS [2]'? –
這是我想用作緩存的hadoop目錄中的txt文件位置。例如。 /user/DeliveryStatusCodes.txt – cody123