First talk about some of the problems encountered:
1, such as the configuration of this if the point Eclipse Red Fork,. Import is the wrong thing to be imported .... There are several classes or methods that can present this problem.
2, with a few online code, inexplicably wrong, and then read their own book combined with the online code to change the following version
3, byte[] array opened relatively large and then write, there will be a problem is written a lot of 0, my method is more stupid, to string judgment, for 0 after the do not write.
I realized the function is to read the contents of the file, delete, in creating a file with the same name to write new things
Import Java.net.uri;import java.util.arrays;import Java.io.*;import Org.apache.hadoop.io.*;import Org.apache.hadoop.conf.configuration;import Org.apache.hadoop.fs.*;import Org.apache.hadoop.fs.filesystem;public Class Filesystemcat {public static void main (string[] args) throws ioexception{string uri = Args[0]; String uro = args[0]; Configuration conf = new configuration (), try {FileSystem fs = Filesystem.get (Uri.create (URI), conf);//filesystem HDFs = Fi Lesystem.get (Uri.create (Uro), conf); Fsdatainputstream in = Fs.open (new Path (URI));//ioutils.copybytes (in, System.out,4096,false);//in.seek (1);// Ioutils.copybytes (in, system.out,4096, false);//file read byte[] Iobuffer = new byte[1024]; int readlen = In.read (Iobuffer); while (readlen!=-1) {Readlen = In.read (Iobuffer); } String str = new string (Iobuffer); int cnt=0; while ((int) (Str.charat (CNT))! = 0) cnt++; Str=str.substring (0, CNT); System.out.println (str); In.close (); Deletion of the file Fs.delete (new Path (URI), true); File writes Fsdataoutputstream out = Fs.create (new Path (Uro)); Out.write (("New1" +str). GetBytes ("UTF-8")); Out.flush (); Out.sync (); Out.close (); Fs.close ();} catch (Exception e) {e.printstacktrace ();}}}
Hadoop writes, deletes, and reads files to HDFs