celine_chen 2016-07-29 05:47 采纳率: 33.3%
浏览 2084

hdfs中视频文件的读取

我在hdfs中上传了一个视频文件,现在想读取视频文件的一些信息

   String uri = "hdfs://master:9000/input/video1.mp4";
      Configuration conf = new Configuration();
      FileSystem fs = FileSystem.get(URI.create(uri), conf);
      InputStream in = null;
       try {
            in = fs.open(new Path(uri));
        }finally {      
            }
        File source = null;
        inputstreamtofile(in,source);
   Encoder encoder = new Encoder();
   try {
      MultimediaInfo m = encoder.getInfo(source);
      long ls = m.getDuration();
      System.out.println("此视频时长为:"+ls/60000+"分"+(ls/000)/1000+"秒!");
   } catch(Exception e) {
     e.printStackTrace();
   }

其中 inputstreamtofile是想将数据流转化为File
public static void inputstreamtofile(InputStream in,File sor) throws IOException{
OutputStream os = new FileOutputStream(sor);
int bytesRead = 0;
byte[] buffer = new byte[19230720];
while ((bytesRead = in.read(buffer, 0, 19230720)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
in.close();
}

但是运行时候会有空指针异常
Exception in thread "main" java.lang.NullPointerException
at java.io.FileOutputStream.(FileOutputStream.java:212)
at java.io.FileOutputStream.(FileOutputStream.java:171)
at mapreduce.readvideoinfo.inputstreamtofile(readvideoinfo.java:20)
at mapreduce.readvideoinfo.main(readvideoinfo.java:40)

这个应该怎么改呢

  • 写回答

1条回答 默认 最新

  • devmiao 2016-08-04 08:00
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊