一、私有文件夹下的文件存取(/data/data/包名)



Java代码

import
import
import
  
public void
try{  
     FileOutputStream fout = openFileOutput(fileName, MODE_PRIVATE);  
byte
     fout.write(bytes);  
      fout.close();  
     }  
catch(Exception e){  
     e.printStackTrace();  
    }  
}     
  
  
public
"";  
try{  
      FileInputStream fin = openFileInput(fileName);  
int
byte [] buffer = new byte[length];  
      fin.read(buffer);      
"UTF-8");  
      fin.close();      
     }  
catch(Exception e){  
      e.printStackTrace();  
     }  
return
    }




 

二、从resource中的raw文件夹中获取文件并读取数据(资源文件只能读不能写)



Java代码



public
"";  
try{  
        InputStream in = getResources().openRawResource(R.raw.test1);   
int
byte [] buffer = new byte[length];         
        in.read(buffer);          
"UTF-8");     
        in.close();             
       }  
catch(Exception e){  
        e.printStackTrace();          
       }  
return
   }



三、从asset中获取文件并读取数据(资源文件只能读不能写)



Java代码


public
"";  
try{  
     InputStream in = getResources().getAssets().open(fileName);    
int
byte [] buffer = new byte[length];         
        in.read(buffer);             
"UTF-8");      
    }  
catch(Exception e){  
     e.printStackTrace();          
    }  
return
   }