Insert and remove of int array data from Java IO stream

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.