Home > other >  Graphs when using a dictionary table "#" at the back of the map is on the map, the results
Graphs when using a dictionary table "#" at the back of the map is on the map, the results

Time:09-18

Graphs when using a dictionary table "#" at the back of the map is on the map, the results show that the can not find a file path but fill out a dictionary in the map path is no problem, here is the code

Package Testday07_01_lagou;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

Import org, apache hadoop. Fs. The Path;
Import org, apache hadoop. IO. IntWritable;
Import org, apache hadoop. IO. Text;
Import org, apache hadoop. Graphs. The Job;
Import org, apache hadoop. Graphs. Filecache. DistributedCache;
Import org, apache hadoop. Graphs. Lib. Input. FileInputFormat;
Import org, apache hadoop. Graphs. Lib. Output. FileOutputFormat;

Public class lagoudriver {
Public static void main (String [] args) throws IllegalArgumentException, IOException, ClassNotFoundException, InterruptedException, URISyntaxException {
//System. SetProperty (" HADOOP_USER_NAME ", "root");
String inputPath="file:/F:/Text/lagou/lagou. TXT".
String outPath="file:/F:/Text/lagou/lagouOut5";
String dicpath="file:/F:/Text/lagou/lagoudic. TXT".
//Configuration conf=new Configuration ();

Job Job=Job. GetInstance ();
//job. SetNumReduceTasks (0);
Job. SetJarByClass (lagoudriver. Class);
//job. SetJar (" C: \ \ Users \ \ Fantastic_Rebo \ \ Desktop \ \ wordcount_zxf jar ");
//job. SetJobName (" wordcountzxf ");
Job. SetMapperClass (lagoumapper. Class);
Job. SetReducerClass (lagoureduce. Class);
Job. SetMapOutputKeyClass (Text. Class);
Job. SetMapOutputValueClass (IntWritable. Class);
Job. SetOutputKeyClass (Text. Class);
Job. SetOutputValueClass (IntWritable. Class);

The Path pathdic=new Path (dicpath);
String dicpath2=pathdic. ToUri (). The toString () + "#" + "dic";
DistributedCache. AddCacheFile (new URI (dicpath2), job getConfiguration ());

FileInputFormat. AddInputPath (job, new Path (inputPath));
FileOutputFormat. SetOutputPath (job, new Path (outPath));
Boolean waitForCompletion=job. WaitForCompletion (true);
System. The out. Println (waitForCompletion);


}
}

` ` `
Package Testday07_01_lagou;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Set;

The import javax.mail. Swing. Plaf. Synth. SynthSpinnerUI;

The import org.apache.com mons. Lang. StringUtils;
Import org, apache hadoop. IO. IntWritable;
Import org, apache hadoop. IO. LongWritable;
Import org, apache hadoop. IO. Text;
Import org, apache hadoop. Graphs. Mapper;

Public class lagoumapper extends Mapper {

HashMap Hm=new HashMap<> (a);
BufferedReader br=null;

@ Override
Protected void setup (Mapper The Context Context)
Throws IOException, InterruptedException {
Br=new BufferedReader (new InputStreamReader (new FileInputStream (" dic ")));
Try {
While (br) ready ()) {
String readLine=br. ReadLine ();
String [] line=readLine. Split (", ");
If (hm!=null) {
Hm. Put (line [0], readLine);
}
}
} the catch (Exception e) {
//TODO: handle the exception
e.printStackTrace();
} the finally {
If (br!=null)
br.close();
}

}

@ Override
Protected void map (LongWritable key, the Text value, Mapper The Context Context)
Throws IOException, InterruptedException {
String [] lines=value. The toString (). The split (", ");
String code=null;
String addr=null;
If (lines. The length==6) {
Code=lines [2];
Addr=lines [lines. Length - 2];
} else {
Code=lines [3].
Addr=lines [lines. Length - 2];
}

//financing round number
String lun=code. The substring (0, 1);
Rongzi context. Write (new Text (", "+ lun), new IntWritable (1));

The distribution of city//
If (addr. The contains (" Beijing ")) {
Set The set=hm. KeySet ();
System.out.println(set);
For (String chengqu: set) {
{if (addr. The contains (chengqu))
String chinessenglishchengqu=hm. Get (chengqu);
The context. Write (new Text (chengqu, "" + chinessenglishchengqu), new IntWritable (1));
}
}
}




}
}

` ` `
The following is a display error


Java. Lang. Exception: Java. IO. FileNotFoundException: dic (the system cannot find the specified file,)
At org, apache hadoop. Mapred. LocalJobRunner $Job. RunTasks (LocalJobRunner. Java: 462)
At org, apache hadoop. Mapred. LocalJobRunner $Job. The run (522) LocalJobRunner. Java:
Under Caused by: Java. IO. FileNotFoundException: dic (the system cannot find the specified file,)
The at Java. IO. FileInputStream. Open0 (Native Method)
The at Java. IO. FileInputStream. Open (FileInputStream. Java: 195)
The at Java. IO. FileInputStream. & lt; init> (a FileInputStream. Java: 138)
The at Java. IO. FileInputStream. & lt; init> (a FileInputStream. Java: 93)
The at Testday07_01_lagou. Lagoumapper. Setup (lagoumapper. Java: 26)
nullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related