InputStream is = getResources().getAsserts().open("Asserts文件夹下的文件名");
InputStreamReader isr=new InputStreamReader(is , "UTF-8" );
BufferedReader br=new BufferedReader(isr);
String str="";
StrigBuffer sb==new StringBuffer();
while((str=br.readLine())!=null)
{
sb.append(str);
}
PS:不是在Activity下
context.getResources()
在 res 文件夹下创建一个名为 Raw 的文件夹, 我一般把大的图片放在raw文件下.
InputStream is = getResources().openRawResource( R.raw.info ); //info 为文件名
InputStreamReader isr=new InputStreamReader(is, "UTF-8");
BufferedReader br=new BufferedReader(isr);
String str="";
StrigBuffer sb==new StringBuffer();
while((str=br.readLine())!=null)
{
sb.append(str);
}
取出大图片
public static Bitmap getBitmap(int rawResource){
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
InputStream is = Global.globalContext.getResources().openRawResource(rawResource);
Bitmap bitmap = BitmapFactory.decodeStream(is,null, opt);
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
PS:不是在Activity下 context.getResources()
String fileName="test";
/* 一、 写入 */
FileOutputStream fos = openFileOutput( filename, Content.MODE_PRIVATE); //写入模式为私有的
OutputStreamWriter osw=new OutputStreamWriter(fos, "UTF-8" );
osw.writeString("fadsfdasfasfsdafasfdasfasdfasdf名字啊!");
osw.flush();
fos.flush();
osw.close()
fos.close();
/* 二、读取 */
FileInputStream fis = openFileInput( fileName );
InputStreamReader isr = new InputStreamReader( fis , "UTF-8" );
char[] input=new char[ fis.available() ];
isr.read(input);
isr.close();
fis.close();
System.out.println( input.toString() );
PS:不是在Activity下 context.openFileOutput()
File sdcard = Environment.getExternalStorageDirectory(); //获取SDCard的路径
File myFile=new File ( scdrd, "TextFolder" ); //后面,为名字
if( ! sdcard.exists( ) )
{
//不存在SDCard
}
myFile.createNewFile();
// 写入
FileOutputStream fos = new FileOutputStream(myFile);
OutputStreamWriter osw = new OutputStreamWitter(fos, "UTF-8");
osw.witer("afadsfdasfa");
osw.flush();
osw.close();
fos.close();
SharedPrefences prefences =getPreferences(Activity.MODE_PRIVATE);
Editor editor = prefences.edit();
String key="myValue";
editor.putString( myValue, "123456");
editor.putInt("ab", 1)
editor.putFloat("flos" ,2.4 );
boolear ok = editor.commit();
if(ok)
{ 输出成功 }
else
{ 输出失败 }
SharedPrefences prefences =getPreferences(Activity.MODE_PRIVATE);
String str = preferences.getString(key, "数值不存在时的默认值" );
int i=preferences.getInt("ab", 0 );
float f = preferences.getFloat("flos" , 0.0f );
File sdcard = Environment.getExternalStroageDirectory () ;
File myFile = new File (sdcard ,"fileName.txt") ; //文件名
//注意权限.....android.permission.WRITE_EXTEAGE_STORAGE....
if( !sdcard.exists())
{
//没有内存卡
return ;
}
FIleInputStream fis = new FileInputSteam(myFile);
InputStreamReader isr = new InputStreamReader(fis ,"UTF-8" );
class db extends SQLiteOpenHelper
{
//构造方法
public db(Context context,String name,CursorFactoty factory ,int version)
{}
@override
oncreate(SQLiteDatabase dbs)
{
db.execSQL("create table "+"sqlname"+"(name text,path text,)")
}
@override
public void onUpgrade()
{
}
}
public Drawable getApkIcon(Context context, String apkPath)
{
PackageManager pm = context.getPackageManager();
PackageInfo info=pm.getPackageArchiveInfo(apkPath,PackageManager.GET_ACTIVITIES);
if(info != null)
{
ApplicationInfo appInfo = info.applicationInfo;
appInfo.sourceDir = apkPath;
appInfo.publicSourceDir = apkPath;
try
{
String label = appInfo.loadLabel(pm).toString();
Log.e("应用中文名:", label);
String packageName = appInfo.packageName;
Log.e("包名:", packageName);
return appInfo.loadIcon(pm);
}
catch(OutOfMemoryError e)
{
Log.e("ApkIconLoader", e.toString());
}
}
return null;
}