tags:

views:

47

answers:

1

I am new to android and I want to read a binary file extension .AMF file.

I really need your help this is really urgent.

Thanks in advance.

I made a folder in RES named raw. Here is the code I tried, it says file not found.

 FileInputStream in = new FileInputStream("R.raw.hello.txt");
 StringBuffer inLine = new StringBuffer(); 
 InputStreamReader isr = new InputStreamReader(in);    
 BufferedReader inRd = new BufferedReader(isr); 
 String text; 

 while ((text = inRd.readLine()) != null) {
   inLine.append(text);
   inLine.append("\n");
 }
 in.close();
 return inLine.toString();
A: 

From the Andoid SDK:

To read a file from internal storage:

Call openFileInput() and pass it the name of the file to read. This returns a FileInputStream. Read bytes from the file with read().

Then close the stream with close().

Tip: If you want to save a static file in your application at compile time, save the file in your project res/raw/ directory. You can open it with openRawResource(), passing the R.raw. resource ID. This method returns an InputStream that you can use to read the file (but you cannot write to the original file).

 InputStream input = getResources().openRawResource(R.raw.hello.txt);
Nix