This article describes how to use filesystem. copyfromlocalfile in intellij idea to operate hadoop. Permission denied is caused by incorrect URI format.
Environment: Mac OS X 10.9.5, intellij idea 13.1.4, hadoop 1.2.1
Hadoop is stored in a virtual machine. The host machine is connected through SSH, And the IDE and data files are stored in the host machine.
The operation code is as follows:
1 public class copyfromlocaltestdriver {2 public static void main (string [] ARGs) {3 configuration = new configuration (); 4 try {5 filesystem = filesystem. get (New uri ("hadoopalice"), configuration); 6 7 path DST = New Path ("/D1 /"); 8 path src = New Path ("/users/Michael/desktop/hadoop/books/easyhadoop .doc"); 9 10 filesystem. copyfromlocalfile (SRC, DST); 11 12 Boolean exists = filesystem. exists (New Path ("/D1/easyhadoop .doc"); 13 system. out. println ("file easyhadoop .doc exists status:" + exists); 14} catch (ioexception e) {15 E. printstacktrace (); 16} catch (urisyntaxexception e) {17 E. printstacktrace (); 18} 19} 20}
Corresponding directories are also available in hadoop.
Prompt for execution
Well, you bullied me. It must be. The previous figure shows that I have access permissions.
Okay, that is to say, the problem should not be on hadoop. Check the code again.
Line 3 of the Code does not seem to comply with the URI rules when constructing a URI. According to section 7 of chapter 7 of "URI section" of elliotte Rusty Harold. Java Network Programming 3rd edition
A URI reference consists of three parts: pattern, pattern-specific, and fragment identifier. The general format is:
Scheme: Scheme-specific-part: Fragment
Compare the filesystem = filesystem. Get (New uri ("hadoopalice"), configuration) in row 5th. If the pattern part is missing, it is a relative Uri. For convenience, add the mode to solve this problem simply and rudely, and continue to learn later.
Filesystem = filesystem. Get (New uri ("HDFS: // hadoopalice: 9000"), configuration );
Run the command again. The result is as follows:
Query hadoop and find that the file is indeed submitted.
Hadoop on Mac with intellij idea-2 resolving URI errors resulting in permission denied