转化流Demon02

Posted Leizi-go

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了转化流Demon02相关的知识,希望对你有一定的参考价值。

package test2;

import java.io.*;

//转换流
public class Demo03
public static void main(String[] args)

FileOutputStream fos = null;
FileInputStream fis = null;
InputStreamReader isr = null;
try
fos = new FileOutputStream("H:\\\\Java2234\\\\Test.txt");

fos.write("北京".getBytes("GBK"));
fos.write("北京".getBytes("UTF-8"));

fos.flush();

fis = new FileInputStream("H:\\\\Java2234\\\\Test.txt");

isr = new InputStreamReader(fis);

int readData;

while ((readData = isr.read()) != -1)
System.out.println((char)readData);


catch (FileNotFoundException e)
e.printStackTrace();
catch (IOException e)
e.printStackTrace();
finally
if (fos != null)
try
fos.close();
catch (IOException e)
e.printStackTrace();


if (isr != null)
try
isr.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结果:

  技术分享

以上是关于转化流Demon02的主要内容,如果未能解决你的问题,请参考以下文章

对象专用流Demon03

linux下如何用php读取word

Hadoop wordcount Demon

Interceptor Demon

Demon_动画控制(实现前后左右移动,喊叫)

Hyper Demon拆解