Java IO Stream Everyone is familiar with it, sometimes if the use of not familiar with the data processing is really a headache, the following is the processing of an array of int.
Here's the code:
public class Stream {private int a[]; Private BufferedWriter BufferedWriter; Private BufferedReader BufferedReader; Private String pathname= "E:\\stream.txt";p rivate void random () {random random=new random (10000); A=new int[10000];for ( int i=0;i<a.length;i++) {a[i]=random.nextint (10000);}} private void Write () {String write=inttostring (a); try {bufferedwriter=new bufferedwriter (new FileWriter (PathName)); Bufferedwriter.write (write); Bufferedwriter.close ();} catch (IOException e) {e.printstacktrace ();}} private void Read () {try {bufferedreader=new BufferedReader (new FileReader (PathName)); String read=bufferedreader.readline (); int[] Array=stringtoint (read); for (int i=0;i<array.length;i++) { System.out.println (Array[i]);}} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ()}} Private String inttostring (int[] a) {StringBuilder stringbuilder=new StringBuilder (); for (int i=0;i<a.length;i++) { Stringbuilder.append (A[i]). Append (",");} StringbuIlder.deletecharat (Stringbuilder.length ()-1); return stringbuilder.tostring ();} Private int[] Stringtoint (String str) {string[] strary = Str.split (","); int[] ary=new int[strary.length];for (int i=0;i <strary.length;i++) {ary[i]=integer.parseint (strary[i]);} return ary;} public static void Main (string[] args) {stream stream =new stream (); Stream.random (); Stream.Write (); Stream.read (); }}
Here for the int array processing is to add a "," separated, and then with a string of split () processing, I hope to be helpful to everyone.
Insert and remove of int array data from Java IO stream