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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法