u012554102
ShawshankLin
2015-08-19 16:14
采纳率: 54.8%
浏览 2.9k
已采纳

hadoop下的存储在hdfs中的视频文件怎么播放?

hadoop下的存储在hdfs中的视频文件怎么播放?可以直接拿到视频文件的http路径吗,我现在想实现的是像百度云这样的可以在线播放,但是不知道怎么得到文件的路径,而hdfs提供的API只有上传下载文件这些,对于这样的问题要怎么解决呢??

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • oyljerry
    oyljerry 2015-08-20 03:10
    已采纳

    你需要用HDFS API来获取

     package org.myorg.hdfsdemo;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileStatus;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    
    
    
    public class HdfsDemo {
    
        public static void main(String[] args) throws IOException {
    
            Configuration conf = new Configuration();
            conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/core-site.xml"));
            conf.addResource(new Path("/Users/miqbal1/hadoop-eco/hadoop-1.1.2/conf/hdfs-site.xml"));
            FileSystem fs = FileSystem.get(conf);
            System.out.println("Enter the directory name :");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            Path path = new Path(br.readLine());
            displayDirectoryContents(fs, path);
        }
    
        private static void displayDirectoryContents(FileSystem fs, Path rootDir) {
            // TODO Auto-generated method stub
            try {
    
                FileStatus[] status = fs.listStatus(rootDir);
                for (FileStatus file : status) {
                    if (file.isDir()) {
                        System.out.println("This is a directory:" + file.getPath());
                        displayDirectoryContents(fs, file.getPath());
                    } else {
                        System.out.println("This is a file:" + file.getPath());
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
    点赞 评论
  • caozhy
    点赞 评论

相关推荐