title: unable to execute hadoop fs -put command from Java
body: <p>I am trying to execute <code>hadoop fs -put &lt;source&gt; &lt;destination&gt;</code> from Java code. When I execute this command directly from the terminal, it works fine but when I try to execute this command from within the Java code using </p>
  
  <pre><code>String[] str = {"/usr/bin/hadoop","fs -put", source, dest};
  Runtime.getRuntime().exec(str);
  </code></pre>
  
  <p>I get error as <code>Error: Could not find or load main class fs</code>. I tried to execute some non-hadoop commands like ls,mkdir commands from Java and they worked fine but the hadoop commands are not getting executed even though they work fine from the terminal.</p>
  
  <p>What could be the possible reason for this and how can I solve it?</p>
  
  <p><strong>JAVA API TRY:</strong> I tried to use java api to perform the copy operation but I get error. The Java code is :</p>
  
  <pre><code>        String source = "/home/tmpe/file1.csv";
          String dest = "/user/tmpe/file1.csv";
          Configuration conf = new Configuration();
          conf.set("fs.defaultFS", "hdfs://node1:8020");
          FileSystem fs = FileSystem.get(conf);
          Path targetPath = new Path(dest);
          Path sourcePath = new Path(source);
          fs.copyFromLocalFile(false,true,sourcePath,targetPath);
  </code></pre>
  
  <p>The error which I get is:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Mkdirs failed to create /user/tmpe
      at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:378)
      at org.apache.hadoop.fs.ChecksumFileSystem.create(ChecksumFileSystem.java:364)
      at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:564)
      at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:545)
      at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:452)
      at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:229)
      at org.apache.hadoop.fs.FileSystem.copyFromLocalFile(FileSystem.java:1230)
  </code></pre>
  
  <p>I have already created <code>/user/tmpe</code> folder  and it has full read-write permissions but still this error comes. I am unable to get the issue resolved</p>