On Thu, May 7, 2009 at 1:26 PM, Foss User <foss...@gmail.com> wrote: > I was trying to write a Java code to copy a file from local system to > a file system (which is also local file system). This is my code. > > package in.fossist.examples; > > import java.io.File; > import java.io.IOException; > import org.apache.hadoop.conf.Configuration; > import org.apache.hadoop.fs.Path; > import org.apache.hadoop.fs.LocalFileSystem; > import org.apache.hadoop.fs.FileUtil; > > public class FileOps > { > public static void main(String[] args) throws IOException > { > FileUtil.copy(new File("a.txt"), > new LocalFileSystem(), >
You can't create a FileSystem like this. You should do something like: Path src = new Path("a.txt"); Path dst = new Path("b.txt"); Configuration conf = new Configuration(); FileUtil.copy(src.getFileSystem(conf), src, dst.getFileSystem(conf), dst, false, conf); > new Path("b.txt"), > false, > new Configuration()); > } > } > > This is the error: > > ubuntu:/opt/hadoop-0.19.1# bin/hadoop jar fileops-0.1.jar > in.fossist.examples.FileOps > java.lang.NullPointerException > at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:375) > at org.apache.hadoop.fs.FileSystem.create(FileSystem.java:367) > at org.apache.hadoop.fs.FileUtil.copy(FileUtil.java:286) > at in.fossist.examples.FileOps.main(Unknown Source) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:597) > at org.apache.hadoop.util.RunJar.main(RunJar.java:165) > at org.apache.hadoop.mapred.JobShell.run(JobShell.java:54) > at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65) > at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:79) > at org.apache.hadoop.mapred.JobShell.main(JobShell.java:68) > > Please help me to fix this error. >