java特殊字符FS_Java FSDataInputStream.readUTF方法代碼示例

import org.apache.hadoop.fs.FSDataInputStream; //導入方法依賴的package包/類

public int run(String[] args, PrintStream stream) throws Exception {

out = stream;

List paths = parseArgs(args);

if (paths.size() != 1) {

errorln(USAGE);

return E_USAGE;

}

println("Hadoop %s", getVersion());

println("Compiled by %s on %s", getUser(), getDate());

println("Compiled with protoc %s", getProtocVersion());

println("From source with checksum %s", getSrcChecksum());

Configuration conf = getConf();

Path path = new Path(paths.get(0));

FileSystem fs = path.getFileSystem(conf);

println("Filesystem for %s is %s", path, fs);

// examine the FS

Configuration fsConf = fs.getConf();

for (int i = 0; i < props.length; i++) {

showProp(fsConf, (String) props[i][0], (Boolean) props[i][1]);

}

Path root = fs.makeQualified(new Path("/"));

try (DurationInfo d = new DurationInfo(LOG,

"Listing %s", root)) {

println("%s has %d entries", root, fs.listStatus(root).length);

}

String dirName = "dir-" + UUID.randomUUID();

Path dir = new Path(root, dirName);

try (DurationInfo d = new DurationInfo(LOG,

"Creating a directory %s", dir)) {

fs.mkdirs(dir);

}

try {

Path file = new Path(dir, "file");

try (DurationInfo d = new DurationInfo(LOG,

"Creating a file %s", file)) {

FSDataOutputStream data = fs.create(file, true);

data.writeUTF(HELLO);

data.close();

}

try (DurationInfo d = new DurationInfo(LOG,

"Listing %s", dir)) {

fs.listFiles(dir, false);

}

try (DurationInfo d = new DurationInfo(LOG,

"Reading a file %s", file)) {

FSDataInputStream in = fs.open(file);

String utf = in.readUTF();

in.close();

if (!HELLO.equals(utf)) {

throw new IOException("Expected " + file + " to contain the text "

+ HELLO + " -but it has the text \"" + utf + "\"");

}

}

try (DurationInfo d = new DurationInfo(LOG,

"Deleting file %s", file)) {

fs.delete(file, true);

}

} finally {

try (DurationInfo d = new DurationInfo(LOG,

"Deleting directory %s", dir)) {

try {

fs.delete(dir, true);

} catch (Exception e) {

LOG.warn("When deleting {}: ", dir, e);

}

}

}

// Validate parameters.

return SUCCESS;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值