Beinsearch
11/20/2017 - 2:11 AM

hadoop

import java.io.InputStream;
import java.net.URI;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.apache.hadoop.io.IOUtils;
import java.io.*;

public class FileSystemCat
{
    public static void main(String[] args) throws Exception {
        String path = "hdfs://master:9000/robot/robot_vpe_20000-40000_join2.txt";
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(URI.create(path), conf);
        FSDataInputStream hdfsInStream = fs.open(new Path(path));
        InputStreamReader isr = new InputStreamReader(hdfsInStream, "utf-8");
        BufferedReader br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }
    }
}

maven pom.xml:
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-client</artifactId>
        <version>2.7.4</version>
    </dependency>
    </dependencies>
#打开pyspark
#cd /home/hadoop/spark-2.0.1-bin-hadoop2.7
#bin/pyspark

lines = sc.textFile("hdfs://master:9000/AI数据/joint_state.txt")
lines = lines.flatMap(lambda line: line.split(" "))
#查看文件列表
hadoop fs -ls hdfs://master:9000/

#查看文件
hadoop fs -cat hdfs://master:9000/AI数据/joint_state.txt

#递归删除文件夹
hadoop fs -rm -r hdfs://master:9000/AI数据/out