【问题标题】:I cannot find the file I am trying to read with my filereader class我找不到我试图用我的文件阅读器类读取的文件
【发布时间】:2011-08-09 10:31:52
【问题描述】:

我创建了一个名为 ECGFilereader 的文件阅读器类,它应该打开一个 .txt,但是当我调试它时,它会将 FileNotFoundException 抛出到使用 txt.file 的 Waveform 类

下面是我的代码,任何帮助或建议将不胜感激。

ECGFilereader.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class ECGFilereader {

    public final static int numChannels = 12;
    public final static int numSamples = 500*6; //500 = fs so *6 for 6 seconds of data
    private File file;
    private Scanner scanner;
    int [] [] ecg = new int [numChannels] [numSamples];
    /*private String path;
    public ECGFilereader(String file_path){
        path = file_path;
    } */

     public ECGFilereader (String fname) throws FileNotFoundException 
     {
        file = new File("res/raw/ecg.txt");
        scanner = new Scanner(file);
    }

    public boolean ReadFile(Waveform[] waves) 
    {
        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] = scanner.nextInt();     
            }
        }
        for (int chan=0; chan<numChannels; chan++)
            waves[chan].setSignal(ecg[chan]);
        return false;

    }

}

波形.java

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PointF;

public class Waveform {

    private int[] signal;


    public void setSignal(int [] x)
    {
        signal = new int[x.length];
        for (int n = 0; n < x.length; n++)
            signal[n] = x[n];
    }

    public void drawSignal(Canvas c, PointF pos)
    {
        Paint paint = new Paint();
        //paint.setColor(getResources().getColor(R.color.ECG_WaveI));
        paint.setColor(Color.BLACK);
        paint.setStyle(Style.STROKE);

        Path path = new Path();
            path.moveTo(pos.x, pos.y);

            for (int n=1; n<ECGFilereader.numSamples; n++)
                path.lineTo(pos.x, (pos.y+signal[(int) n]));
                c.drawPath(path, paint);
    }

}

【问题讨论】:

    标签: android file text filepath


    【解决方案1】:

    您不能直接访问 res 文件夹中的文件。如果您想访问原始文件夹中的文件,请尝试getResource().openRawResource(int id)

    请看这里:raw Resources Android filepath

    【讨论】:

    • 感谢您的快速响应,但事实证明保存在原始文件夹中是完全错误的,我需要将数据存储在 sd 卡上,我应该能够做到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多