我想在java中读取.rc文件并将其内容存储在hashmap中。 .rc ext文件是C / C ++中使用的资源文件,我想用java开发应用程序。 请帮忙。在此先感谢。
public static void main(String[] args){
try
{
JobConf job = new JobConf(new Configuration(), Application.class);
FileSystem fs = FileSystem.get(job);
FileStatus [] fileStatuses = fs.listStatus(new Path("C:/Users/Desktop/fold/"));
LongWritable key = new LongWritable();
BytesRefArrayWritable value = new BytesRefArrayWritable();
int counter = 1;
for (int i = 0; i < fileStatuses.length; i++)
{
FileStatus fileStatus = fileStatuses[i];
if (!fileStatus.isDir())
{
System.out.println("File: " + fileStatus);
FileSplit split = new FileSplit(fileStatus.getPath(), 0, fileStatus.getLen(), job);
RCFileRecordReader reader = new RCFileRecordReader(job, split);
while (reader.next(key, value))
{
System.out.println("Getting row " + counter);
counter++;
}
}
}
}
catch (IOException e)
{
throw new Error(e);
}
}
它给了我例外:
线程“main”中的异常java.lang.Error:java.io.IOException: file:/ C:/Users/Desktop/fold/xyz.rc不是RCFile并且具有I01的魔力 在Application.main(Application.java:119)引起: java.io.IOException:file:/ C:/Users/Desktop/fold/xyz.rc不是RCFile 并拥有I01的魔力 org.apache.hadoop.hive.ql.io.RCFile $ Reader.init(RCFile.java:1269)at at org.apache.hadoop.hive.ql.io.RCFile $读者。(RCFile.java:1154) 在 org.apache.hadoop.hive.ql.io.RCFile $读者。(RCFile.java:1133) 在 org.apache.hadoop.hive.ql.io.RCFileRecordReader。(RCFileRecordReader.java:102) 在Application.main(Application.java:106)
请帮忙
答案 0 :(得分:0)
FileInputStream inputStream = new FileInputStream("C:/Users/Desktop/fold/xyz.rc");
try {
String str = IOUtils.toString(inputStream);
System.out.println(str);
} finally {
inputStream.close();
}