Androidアプリ raw
投稿日: | |
---|---|
修正日: | |
タグ: |
raw
Androidアプリのリソースには,テキストやバイナリなどの生のデータがある.それらのデータはresのrawというディレクトリに格納される.rawへのファイルの追加はEclipseの機能を用いてコピーしたり生成したりすることが望ましい.これはEclipseがリソース情報を管理していることに起因する.
String[] lines;
try {
int i = 0, cnt = 0;
android.content.res.Resources resource = getResources();
java.io.InputStream is = resource.openRawResource(R.raw.text);
while (is.read()!=-1) cnt++;
byte [] b = new byte[cnt+1];
is.reset();
is.read(b);
String str = new String(b);
lines = str.split(";");
is.close();
}catch(java.io.IOException e){
}