文件读写
来源:互联网 发布:最简单的编程软件 编辑:程序博客网 时间:2024/05/11 20:55
1.sdcard文件、自己应用包内部的文件和别的应用包的文件的读取
/*******************************************************************
* 0获取别的apk内部的文件
* 1.获取sdcard的文件
* 2.获取自己内部的文件
*
* *******************************************************************/
private String readFileData(String fileName,int num){
String res=null;
try{
FileInputStream fin=null;
if(num==0)
{
File file = new File(fileName);
// FileInputStream fin = openFileInput(file);
fin = new FileInputStream(file);
Log.v(m_log,"read ID from other apk inside files\n");
}
else if(num==1)
{
fin = new FileInputStream(fileName);
Log.v(m_log,"read ID from SDCARD files\n");
}
else if (num==2)
{
fin = localcontext.openFileInput(fileName);
Log.v(m_log,"read ID from APK inside files\n");
}
else
{
/*****其他的情况************/
Log.v(m_log,"not support this type read file \n");
}
if(fin==null)
return null;
int length = fin.available();
byte [] buffer = new byte[length];
fin.read(buffer);
res = EncodingUtils.getString(buffer, "UTF-8");
fin.close();
Log.v(m_log,"read files sucess\n");
}
catch(Exception e){
Log.v(m_log,"error in read files \n");
//e.printStackTrace();
}
String data=decodeAndcheck(res);
return data;
}
2.写sd卡文件和写文件到应用自己的内部包
/*******************************************************************
* 0写到apk内部的文件
* 1.写到sdcard的文件
*
* *******************************************************************/
private static boolean writeFileData(Context context,String fileName,String message,int num)
{
boolean res=false;
String encode_message=null;
String writemessage=null;
if(message==null)
return false;
// int Stringhash=message.hashCode();
// encode_message=encodedata(message);
// writemessage=encode_message+":"+Stringhash;
try{
FileOutputStream fout=null;
if(num==0)
{
fout =context.openFileOutput(fileName, Context.MODE_WORLD_READABLE);
Log.v(m_log,"write file to inside apk package \n");
}
else if(num==1)
{
fout = new FileOutputStream(fileName);
Log.v(m_log,"write file to sdcard \n");
}
else
{
/*************************/
Log.v(m_log,"not support this type write file to sdcard \n");
}
if(fout==null)
return false;
byte [] bytes = message.getBytes();
fout.write(bytes);
fout.close();
res=true;
Log.v(m_log,"write file sucess \n");
}
catch(Exception e){
Log.v(m_log,"error in write file to apk \n");
e.printStackTrace();
}
return res;
}
3.System.loadLibrary的失败被接受的时间是UnsatisfiedLinkError;
- 文件读写、剪贴板读写
- 读写文件
- 文件读写
- 读写文件
- 读写文件
- 文件读写
- 读写文件
- 读写文件
- 读写文件
- 文件读写
- 文件读写
- 文件读写
- 文件读写
- 读写文件
- 文件读写
- 文件读写
- 文件读写
- 文件读写
- 修改tomcat server.xml配置文件,解决乱码问题
- js文件操作
- cocos2d-x 开发中使用的一些工具
- li中内容太长,用省略号显示
- 独立android开发者开发app如何盈利
- 文件读写
- org.apache.hadoop.security.AccessControlException: Permission denied: user=root
- 2013年2月,5年C++开发者找工作经历
- bash参考手册之四(shell内建命令)续一
- Linux文件系统简介
- 找出数组中和为给定值的两个数
- 解决Firefox和Chrome上福州大学教务处下拉菜单无法显示问题
- android对json数据解析的封装
- 浏览器的想象空间在哪里?