Android小部件读取openFileInput

时间:2015-11-17 20:46:42

标签: java android widget text-files readfile

所以我对这个应用程序的制作都很陌生。

我尝试使用该命令到达文件 InputStream inputStream = openFileInput("files.txt");它给了我错误"无法解决方法openFileInput(java.lang.String)"。我的资源或资源中没有保存文件,它保存在我保存的任何地方当你在应用程序中创建它时。

问题

  1. 我可以在小部件中阅读文件吗
  2. 如果是这样,为什么这不起作用?
  3. 功能

    private void readFiles() throws IOException 
    {
        cards.removeAll(cards);
        InputStream inputStream = openFileInput("files.txt");
        if(inputStream != null){
            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            int size = Integer.parseInt(bufferedReader.readLine());
            for(int i = 0; i < size; i++){
                card tmp = new card();
                tmp.setAlias(bufferedReader.readLine());
                tmp.setIconID(Integer.parseInt(bufferedReader.readLine()));
                tmp.setId(bufferedReader.readLine());
                tmp.setRemaining(Integer.parseInt(bufferedReader.readLine()));
                tmp.setDescription(bufferedReader.readLine());
                tmp.setPeriodStartDate(bufferedReader.readLine());
                tmp.setPeriodEndDate(bufferedReader.readLine());
                tmp.setPeriodRemaining(Integer.parseInt(bufferedReader.readLine()));
                tmp.setWaitingPeriods(Integer.parseInt(bufferedReader.readLine()));
                tmp.setUnFetched(Integer.parseInt(bufferedReader.readLine()));
                tmp.setNameDescription(bufferedReader.readLine());
                tmp.setCardExpiryDate(bufferedReader.readLine());
                tmp.setCardStatus(bufferedReader.readLine());
                tmp.setDaysUntilCardExpiry(bufferedReader.readLine());
                cards.add(tmp);
            }
            inputStream.close();
        }
    }
    

0 个答案:

没有答案