问题描述
- hadoop下的存储在hdfs中的视频文件怎么播放?
-
hadoop下的存储在hdfs中的视频文件怎么播放?可以直接拿到视频文件的http路径吗,我现在想实现的是像百度云这样的可以在线播放,但是不知道怎么得到文件的路径,而hdfs提供的API只有上传下载文件这些,对于这样的问题要怎么解决呢??
解决方案
你需要用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();
}
}
}
解决方案二:
hdfs支持随机读文件
http://blog.csdn.net/xhh198781/article/details/6944516
http://shiyanjun.cn/archives/962.html
解决方案三:
hadoop存储视频文件
时间: 2024-10-31 00:56:24