作者sweet00914 (别理我)
看板AndroidDev
标题Re: [问题] 读取文字档(/raw;/assets;/res)
时间Fri Dec 30 15:48:28 2011
※ 引述《sweet00914 (别理我)》之铭言:
: ※ 引述《givemepass (〆)》之铭言:
: : 把你的档案放在assets里面
: : 我假设你的档案叫做 my_text_file.txt
: : 然後我复制一份存到sdcard下面/sdcard/text_file.txt
: : 就可以拿这个来读取
: : public class TestRandomFileAccessActivity extends Activity {
: : /** Called when the activity is first created. */
: : @Override
: : public void onCreate(Bundle savedInstanceState) {
: : super.onCreate(savedInstanceState);
: : setContentView(R.layout.main);
: : //先取得资产管理员
: : AssetManager assetManager = this.getApplicationContext().getAssets();
: : try {
: : //用资产管理员打开文字档 变成串流
: : InputStream inputStream = assetManager.open("my_text_file.txt");
: : byte[] b = new byte[1024];
: : int len = -1;
: : File file = new File("/sdcard/text_file.txt");
: : FileOutputStream outputStream = new FileOutputStream(file);
後来我使用
RandomAccessFile random = new RandomAccessFile(
File.createTempFile( "test" , "tmp" ), "rwd" );
来建立档案。这样子一来,等待程式结束後,新增的暂存档也会被删除。
而不会永远停留在sd卡上~
不知道大家有何建议?0.0
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.130.55.241
1F:→ KeySabre:不知道你的出发点是什麽 我自己觉得是能不IO就尽量不IO 12/30 19:49