【发布时间】:2016-09-29 11:02:58
【问题描述】:
我有一个 HashMap >。我想将我的 HashMap 对象(hmap)序列化到 HDFS 位置,然后在 Mapper 和 Reducers 将其反序列化以使用它。
为了在 HDFS 上序列化我的 HashMap 对象,我使用了如下的普通 java 对象序列化代码,但出现错误(权限被拒绝)
try
{
FileOutputStream fileOut =new FileOutputStream("hashmap.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(hm);
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}
我遇到了以下异常
java.io.FileNotFoundException: hashmap.ser (Permission denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
at java.io.FileOutputStream.<init>(FileOutputStream.java:110)
at KMerIndex.createIndex(KMerIndex.java:121)
at MyDriverClass.formRefIndex(MyDriverClass.java:717)
at MyDriverClass.main(MyDriverClass.java:768)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
有人可以建议或分享如何在 hdfs 上的 hadoop 中序列化对象的示例代码吗?
【问题讨论】:
-
这似乎是文件权限问题。但是为了简单起见,请检查我的答案
标签: java hadoop serialization mapreduce bigdata