• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help InputStream to number[]

Hi everyone, I'm new to Android Studio and i have as issue. I'm trying to read an file and save a column in to Number[].

the file that should be read looks like:

Code:
----------------------------------------------------
Curve: ECG CH1,    size: 1694
Index,    Time [Seconds],    ECG CH1: Input Voltage [V]
----------------------------------------------------
0,    4.000000,    0.001806
1,    4.001172,    0.001845
2,    4.002345,    0.001869
3,    4.003517,    0.001862
.......
1692,    5.983587,    0.023331
1693,    5.984760,    0.023321

I did these:
  1. save the txt file in asset folder.
  2. opened it by InputStream.
  3. Saved it in byte[] to display it (to make sure it's there)
And now I want to use these data and save the last column of the file into a number[] to graph it using android plot. (API 19 that I'm using)

and my MainActivity.java is:

Java:
package com.fatoomh.trial_1;

import android.content.res.AssetManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.TextView;

import java.io.IOException;
import java.io.InputStream;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView txtContent = (TextView) findViewById(R.id.tv1);

        String[] value;
        String line;


        // get the file from asset
        AssetManager assetManager = getAssets();
        InputStream inputStream ;


        try {
            //open the file
            inputStream = assetManager.open("Data6sec.txt");

            //the size of the string
            int size = inputStream.available();

            byte[] buffer = new byte[size];
            inputStream.read(buffer);
            inputStream.close();

            //show the array
            String text = new String(buffer);
            txtContent.setText(text);

        } catch (IOException e1) {
            e1.printStackTrace();
        }
    }
}

please help me (T.T) ...
 
Back
Top Bottom