本文整理匯總了Java中org.apache.hadoop.hdfs.DistributedFileSystem.exists方法的典型用法代碼示例。如果您正苦於以下問題:Java DistributedFileSystem.exists方法的具體用法?Java DistributedFileSystem.exists怎麽用?Java DistributedFileSystem.exists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.hdfs.DistributedFileSystem
的用法示例。
在下文中一共展示了DistributedFileSystem.exists方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: mapreduce
import org.apache.hadoop.hdfs.DistributedFileSystem; //導入方法依賴的package包/類
@Test
public void mapreduce() {
MapReduceConfiguration mapReduceConfiguration = new MapReduceConfiguration();
DistributedFileSystem distributedFileSystem = mapReduceConfiguration.distributedFileSystem();
try {
String inputPath = mapReduceConfiguration.url() + "/mapreduce/temperature/input";
Path inputpath = new Path(inputPath);
//文件不存在 則將輸入文件導入到hdfs中
if (!distributedFileSystem.exists(inputpath)) {
distributedFileSystem.mkdirs(inputpath);
distributedFileSystem.copyFromLocalFile(true, new Path(this.getClass().getClassLoader().getResource("mapred/temperature/input").getPath()), new Path(inputPath + "/input"));
}
String outputPath = mapReduceConfiguration.url() + "/mapreduce/temperature/mapred/output" + DateFormatUtils.format(new Date(), "yyyyMMddHHmmSS");
ToolRunner.run(new MaxTemperatureMapRed(), new String[]{inputPath, outputPath});
mapReduceConfiguration.print(outputPath);
} catch (Exception e) {
log.error(e);
e.printStackTrace();
} finally {
mapReduceConfiguration.close(distributedFileSystem);
}
}
示例2: moveToTarget
import org.apache.hadoop.hdfs.DistributedFileSystem; //導入方法依賴的package包/類
/**
* Finish the rename operations: move all the intermediate files/directories
* from the tmp dir to the final targets.
*/
private static void moveToTarget(DiffInfo[] diffs,
DistributedFileSystem targetFs) throws IOException {
// sort the diffs based on their target paths to make sure the parent
// directories are created first.
Arrays.sort(diffs, DiffInfo.targetComparator);
for (DiffInfo diff : diffs) {
if (diff.target != null) {
if (!targetFs.exists(diff.target.getParent())) {
targetFs.mkdirs(diff.target.getParent());
}
targetFs.rename(diff.getTmp(), diff.target);
}
}
}