Skip to content

Instantly share code, notes, and snippets.

@wolny
Created January 7, 2016 17:09
Show Gist options
  • Save wolny/353b82ef84949ab78855 to your computer and use it in GitHub Desktop.
Save wolny/353b82ef84949ab78855 to your computer and use it in GitHub Desktop.
Simple code snippet for copying a file from local file system to HDFS
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class HadoopTest {
public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException {
FileSystem hdfs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration(), "slo");
Path localFilePath = new Path("/home/slo/wireshark.out");
Path remoteFilePath = new Path("/home/hadoop/test.txt");
hdfs.copyFromLocalFile(localFilePath, remoteFilePath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment