对象专用流Demon03
Posted Leizi-go
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对象专用流Demon03相关的知识,希望对你有一定的参考价值。
package test2;
import java.io.*;
//对象专用流
public class Demo04
public static void main(String[] args)
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try
fos = new FileOutputStream("H:\\\\Java2234\\\\Test.txt");
oos = new ObjectOutputStream(fos);
Student lucy = new Student("Lucy", 15);
oos.writeObject(lucy);
oos.flush();
catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
finally
if (oos != null)
try
oos.close();
catch (IOException e)
e.printStackTrace();
FileInputStream fis = null;
ObjectInputStream ois = null;
try
fis = new FileInputStream("H:\\\\Java2234\\\\Test.txt");
ois = new ObjectInputStream(fis);
Student stu = (Student) ois.readObject();
System.out.println(stu);
catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
catch (ClassNotFoundException e)
e.printStackTrace();
finally
if (ois != null)
try
ois.close();
catch (IOException e)
e.printStackTrace();
Hadoop wordcount Demon
搭建完成Hadoop后,第一个demon,wordcount。此处参考:http://blog.csdn.net/wangjia55/article/details/53160679
wordcount是hadoop的入门经典.
1.在某个目录下新建若干文件,我在各个文件里都添加了一些英文文章段落:
2.在hadoop-2.7.3目录下创建一个wordcountTest目录:
bin/hdfs dfs -mkdir /wordcountTest
查看刚才建立的目录:
bin/hdfs dfs -ls /
可以发现,已经建立起了wordcountTest目录。
3.将步骤1中本地的text文件上传到hdfs中:
bin/hdfs dfs -put /home/hadoop/hadoop-2.7.3/hadoop_test/*.txt /wordcountTest
查看上传结果:
bin/hdfs dfs -ls /wordcountTest
显示上传已完成。
4.运行wordcount
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /wordcountTest/*.txt /wordcountTest/out.txt
运行结果截图:
查看运行结果:
bin/hdfs dfs -ls /wordcountTest/out.txt/
其中运行结果存储在part-r-00000中。
查看part-r-00000文件内容:
bin/hadoop fs -cat /wordcountTest/out.txt/part-r-00000
截图是部分wordcount结果:
以上是关于对象专用流Demon03的主要内容,如果未能解决你的问题,请参考以下文章