<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 環境搭建 * JAVA * IDEA * MAVEN * pom.xml 要添加cdh倉庫,然后maven install 非常慢。 ~~~ <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.bizzbee.bigdata</groupId> <artifactId>hadoop-train-v2</artifactId> <version>1.0-SNAPSHOT</version> <properties> <hadoop.version>2.6.0-cdh5.15.1</hadoop.version> </properties> <!-- 添加倉庫--> <repositories> <repository> <id>cloudera</id> <url>https://repository.cloudera.com/artifactory/cloudera-repos</url> </repository> </repositories> <dependencies> <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-client</artifactId> <version>${hadoop.version}</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> </project> ~~~ ## hdfs API測試 >單機的hadoop測試環境要加上下面這句配置。 > configuration.set("dfs.client.use.datanode.hostname", "true"); ![](https://img.kancloud.cn/0f/72/0f72abc41284d40822e6fad0b783f47d_352x201.png) ~~~ public class HDFSApp { public static final String HDFS_PATH = "hdfs://tencent2:8020"; Configuration configuration; FileSystem fileSystem; @Before public void setUp() throws URISyntaxException, IOException, InterruptedException { configuration = new Configuration(); //我去,下面這句話相當重要啊!不然讀取文件有問題啊!!! configuration.set("dfs.client.use.datanode.hostname", "true"); fileSystem = FileSystem.get(new URI(HDFS_PATH),configuration,"bizzbee"); } /* * 讀取文件 * */ @Test public void text() throws IOException { FSDataInputStream in =fileSystem.open(new Path("/bizzbee/test/cba")); IOUtils.copyBytes(in,System.out,1024); } /* * 創建文件 * */ @Test public void create() throws Exception{ FSDataOutputStream out = fileSystem.create(new Path("/bizzbee/test/nba.txt")); out.writeUTF("湖人總冠軍!"); out.flush(); out.close(); } /* * 重命名 * */ @Test public void rename() throws Exception{ Path oldP = new Path("/bizzbee/test/nba.txt"); Path newP = new Path("/bizzbee/test/cba.txt"); boolean r = fileSystem.rename(oldP,newP); System.out.println(r); } /* * 創建文件夾*/ @Test public void mkdir () throws Exception{ fileSystem.mkdirs(new Path("/bizzbee/test")); } /* * 拷貝本地文件到文件系統 * */ @Test public void copyFromLocalFile() throws Exception{ Path from = new Path("/Users/bizzbee/IdeaProjects/hadooptrainv2/pom.xml"); Path to = new Path("/bizzbee/test/pom.xml"); fileSystem.copyFromLocalFile(from,to); } /* * 拷貝本地大型文件 * 帶進度條 * */ @Test public void copyFromLocalBigFile() throws Exception{ //本地讀一個大文件 InputStream in = new BufferedInputStream(new FileInputStream(new File("/Users/bizzbee/python/python-3.7.0-macosx10.9.pkg"))); //往hdfs輸出流。 FSDataOutputStream out = fileSystem.create(new Path("/bizzbee/test/python-mac1.pkg"), new Progressable() { public void progress() { System.out.print("."); } }); IOUtils.copyBytes(in,out,4096); } /* * 下載文件,拷貝到本地 * */ @Test public void copyToLocalFile() throws Exception{ Path from = new Path("/bizzbee/test/cba.txt"); Path to = new Path("/Users/bizzbee/Desktop/cba.txt"); fileSystem.copyToLocalFile(from,to); } /* * 列出所有文件 * */ @Test public void listFiles() throws Exception{ FileStatus[] statuses = fileSystem.listStatus(new Path("/bizzbee/test")); for (FileStatus file:statuses){ String isDir = file.isDirectory()? "file":"dir"; String permission = file.getPermission().toString(); short rep = file.getReplication(); long length = file.getLen(); String path = file.getPath().toString(); System.out.println(isDir+"--"+permission+"--"+rep+"--"+length+"--"+path); } } /* * 遞歸展示目錄文件 * */ @Test public void listFilesRecursive() throws Exception{ RemoteIterator<LocatedFileStatus> files = fileSystem.listFiles(new Path("/bizzbee/test"),true); while (files.hasNext()){ LocatedFileStatus file = files.next(); String isDir = file.isDirectory()? "file":"dir"; String permission = file.getPermission().toString(); short rep = file.getReplication(); long length = file.getLen(); String path = file.getPath().toString(); System.out.println(isDir+"--"+permission+"--"+rep+"--"+length+"--"+path); } } /*塊信息*/ @Test public void getFileBlocKLocations()throws Exception{ FileStatus fileStatus = fileSystem.getFileStatus(new Path("/bizzbee/test/python-mac1.pkg")); BlockLocation[] blocks = fileSystem.getFileBlockLocations(fileStatus,0,fileStatus.getLen()); for(BlockLocation block:blocks){ for(String name:block.getNames()) { System.out.println(name + "----" + block.getOffset() + "----" + block.getLength() + "----" + block.getHosts().toString()); } } } @Test public void delete() throws Exception{ boolean result = fileSystem.delete(new Path("/bizzbee/test/python-mac.pkg"),true); System.out.println(result); } @After public void tearDown(){ configuration = null; fileSystem = null; System.out.println("tearDown"); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看