Android Java read SD card text file __ Humanoid robot

Source: Internet
Author: User

In sequence recognition, multiple pattern strings need to be identified, and multiple-line floating-point numbers need to be read and parsed.

So the method used is:

Use text to read multiple lines, regular expression matches for each line of text, and character conversions.

The code is as follows:

        @SuppressLint ("Sdcardpath")         public static void Readtxt2seqmulti (String txtpath,  vector<vector<float > >  Seq) {     & nbsp;        try {                   string encoding= "GBK";                   file file=new File (Txtpath);                   if (file.isfile () && File.exists ()) {//Determine whether the file exists                    & nbsp  inputstreamreader read = new InputStreamReader (              & nbsp;               new fileinputstream (file), encoding); Considering the coding format                       bufferedreader bufferedreader = new BufferedReader (read);                       string linetxt = Null
                      seq.clear ();                                           while (linetxt = Bufferedreader.readline ())!= null) {                      & nbsp;   //input each line to the vector                          //system.out.println (linetxt);                           string[] Sourcestrarray = Linetxt.split ("");
                                                 
Vector<float >   seqs= New Vector<float > ();                           for (int i = 0; i < sourcestrarray.length i++) {                           //system.out.println (sourcestrarray[i)
);                         
    string svalue = sourcestrarray[i];                              float Value =float.parsefloat (svalue);                         
    seqs.add (Value);                         }                        & nbsp
Seq.add (SEQS);                    &nbsp}      & nbsp;                                     read.close ();                   }else{      & nbsp;               system.out.println ("No specified file found");    &nbsp             &nbsp}            & nbsp &NBSP} catch (Exception e) {                   SYSTEM.OUT.PRINTLN ("Error reading file contents");                   e.printstacktrace ();               }           

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.