[HP Top] |
MobileApp > Android > File Access ファイルアクセスの方法 †ファイルアクセスの概要 † Androidではjava.ioパッケージの標準ioが使用できる。ので、特に難しくない ファイル読込 †openFileInput() でStreamを取得し、read()で読み込む // テキストの読込 public void loadText() throws IOException{ String path = "data.txt"; FileInputStream input = this.openFileInput(path); byte[] buffer = new byte[1000]; input.read(buffer); String s = new String(buffer).trim(); edit.setText(s); input.close(); } ファイル書込 †openFileOutput() で Streamを取得し、write()で書き込む // テキストの保存 public void saveText(String data) throws IOException{ String path = "data.txt"; FileOutputStream output = this.openFileOutput(path, Context.MODE_WORLD_READABLE); output.write(data.getBytes()); output.close(); }
SDカード へのアクセス †
File file = Environment.getExternalStorageDirectory(); File file = File("/sdcard");
ディレクトリ構成について †工事中 参考 † Asset Managerの件 |