网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
05月30日漏签0天
新松小学吧 关注:61贴子:2,387
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 1回复贴,共1页
<<返回新松小学吧
>0< 加载中...

java

  • 只看楼主
  • 收藏

  • 回复
  • 10
  • 大名鼎鼎
    14
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
importorg.apache.hadoop.conf.Configuration;
importorg.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import java.io.*;
public class MyFSDataInputStream extendsFSDataInputStream {
public MyFSDataInputStream(InputStream in){
super(in);
}
public static Stringreadline(BufferedReader br) throws IOException {
char[] data = new char[1024];
int read = -1;
int off = 0;
while ( (read = br.read(data, off, 1)) !=-1 ) {
if(String.valueOf(data[off]).equals("\n") ) {
off += 1;
break;
}
off += 1;
}
if (off > 0) {
return String.valueOf(data);
} else {
return null;
}
}
public static void cat(Configuration conf,String remoteFilePath) throws IOException {
FileSystem fs = FileSystem.get(conf);
PathremotePath = new Path(remoteFilePath);
FSDataInputStream in = fs.open(remotePath);
BufferedReader br = new BufferedReader(newInputStreamReader(in));
String line = null;
while ( (line =MyFSDataInputStream.readline(br)) != null ) {
System.out.println(line);
}
br.close();
in.close();
fs.close();
}
public static void main(String[] args) {
Configuration conf = new Configuration();
conf.set("fs.default.name","hdfs://localhost:9000");
String remoteFilePath ="/user/hadoop/text.txt";
try {
MyFSDataInputStream.cat(conf,remoteFilePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}


  • 10
  • 大名鼎鼎
    14
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.IOUtils;
import java.io.*;
import java.net.URL;
public class HDFSApi {
static{
URL.setURLStreamHandlerFactory(newFsUrlStreamHandlerFactory());
}
public static void main(String[] args)throws Exception {
String remoteFilePath ="hdfs:///user/hadoop/text.txt";
InputStream in = null;
try{
in =new URL(remoteFilePath).openStream();
IOUtils.copyBytes(in,System.out,4096,false);
}finally{
IOUtils.closeStream(in);
}
}
}


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1回复贴,共1页
<<返回新松小学吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示