我已經將文件「ecg.text」放入目錄mnt/sdcard/ecg/ecg.text中,然後使用以下代碼來讀取它,但不斷獲取catch(FileNotFoundException) 。任何關於如何找到文件的幫助或建議將不勝感激。從SD卡讀取文件
在此先感謝。
主要活動類:
ECGFilereader reader;
try {
reader = new ECGFilereader("ecg");
reader.ReadFile(waves);
for (int chan=0; chan<ECGFilereader.numChannels; chan++) {
waves[chan].drawSignal(c, (wavePos[chan])); //new Waveform may need to be created
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
和ECGFilereader.java
public class ECGFilereader {
public final static int numChannels = 12; // the data is stored in 12 channels, one for each lead
public final static int numSamples = 500*6; //500 = fs so *6 for 6 seconds of data
public File file;
private Scanner scanner;
short [] [] ecg = new short [numChannels] [numSamples];
public ECGFilereader (String fname) throws FileNotFoundException
{
File dir = Environment.getExternalStorageDirectory(); //accesses the ecg file from the SD card
file = new File(dir, "mnt/sdcard/ecg/ecg.text");
scanner = new Scanner(file);
}
public boolean ReadFile(Waveform[] waves) // sorts data into and array of an array (12 channels each containing 5000 samples)
{
for (int m=0; m<numSamples && scanner.hasNextInt(); m++)
{
int x = scanner.nextInt();
for (int chan = 0; chan<numChannels && scanner.hasNextInt(); chan++)
{
ecg [chan] [m] = (short) scanner.nextInt();
}
}
for (int chan=0; chan<numChannels; chan++)
waves[chan].setSignal(ecg[chan]); // sets a signl equal to the ecg array of channels
return true;
}
}
此外,在公共ECGFilereader,DIR有「到/ mnt/SD卡/」了,所以你不需要再指定它,當你將值值的文件 – Jan
好的,謝謝,我該如何將它放入清單中,因爲我嘗試過只是粘貼^並且也嘗試了但它似乎沒有任何區別。 –
Jacko85
在公共ECGFilereader中,請確保文件=新文件(dir,「/ecg/ecg.text」); – Jan