在android中使用.dat扩展文件

时间:2012-02-16 22:37:22

标签: android

我需要在Android中使用.dat类型的文件,但我无法引用该文件,应用程序没有意识到该文件

该代码是否正确?

File sdcard=Environment.getExternalStorageDirectory();
  File file=new File(sdcard,"dictionary.dat");
  if(file.exists()){
         Toast.makeText(context,"file exists",Toast.LENGTH_LONG).show();
        }
  else{
        Toast.makeText(context,"NOT exists",Toast.LENGTH_LONG).show();
    }
 String path=file.getAbsolutePath();    
 FileInputStream fis=new FileInputStream(path);
 DataInputStream dawgDataFile=new DataInputStream(fis);

也许我的编码方式错误,我只需要使用“dictionary.dat”文件,并将其存储在原始文件夹中。按钮应用程序说“不存在”。请帮忙

1 个答案:

答案 0 :(得分:0)

您无法将文件保存在 RAW 文件夹中。这就是你如何做到的:

InputStream inputStream  = getResources().openRawResource(R.raw.dictionary);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

//then start reading lines from reader with reader.readLine()

P.S。在RAW文件夹中保存文件时,可以省略文件扩展名,因为在代码中引用时它们不可用

相关问题