Fatooom_h_
Lurker
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:
I did these:
and my MainActivity.java is:
please help me (T.T) ...
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:
- save the txt file in asset folder.
- opened it by InputStream.
- Saved it in byte[] to display it (to make sure it's there)
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) ...