Android 我希望其他人解释什么是更好的文件加载或留在内存中

Android 我希望其他人解释什么是更好的文件加载或留在内存中,android,Android,我需要在我的android程序上显示中间文本 我有20种文本 最好的方法是什么: 将文本加载到不同的VAL 从文件加载? 如果最好的方法是从文件2中加载,我可以得到一个示例吗?下面是一些可能有用的代码 public void Data_read(View v) { Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); File root = Environment.ge

我需要在我的android程序上显示中间文本

我有20种文本

最好的方法是什么:

将文本加载到不同的VAL 从文件加载?
如果最好的方法是从文件2中加载,我可以得到一个示例吗?

下面是一些可能有用的代码

public void Data_read(View v) {

        Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);

        File root = Environment.getExternalStorageDirectory();
        TextView tv = (TextView) findViewById(R.id.Read2);
        Toast.makeText(getBaseContext(), "Done reading SD 'mysdfile.txt'",
                Toast.LENGTH_SHORT).show();
        try {
            File myFile = new File(root + "yourfile.txt");
            FileInputStream fIn = new FileInputStream(myFile);
            BufferedReader myReader = new BufferedReader(new InputStreamReader(
                    fIn));
            String aDataRow = "";
            String aBuffer = "";

            while ((aDataRow = myReader.readLine()) != null) {
                aBuffer += aDataRow + "\n";
                Date lastModDate = new Date(myFile.lastModified());
                System.out.println("File last modified @ : "
                        + lastModDate.toString());
            }
            tv.setText(aBuffer);
            myReader.close();

        } catch (Exception e) {
            Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT)
                    .show();
        }
    }
获取一个txt文件,然后读取所有行并将它们放入和文本视图中。 这只是一个示例代码,所以您可能需要对其进行一些更改,以便它适合您自己的代码


如果您对此有任何疑问,可以随时询问。

文本是否在strings.xml文件中?如果不是,为什么不呢?不,文本不在string.xml中,所以最好从文件中加载?对不起,昨天休息了一天。我认为最好是从文件加载,因为您可以更好地控制它。