rawでのファイルの読み込み
1418 ワード
方法一(private Mapheadline Value)
方法2
public String getFromRaw() {
String result = "";
try {
InputStream in = context.getResources().openRawResource(R.raw.cc);
int lenght = in.available();
byte[] buffer = new byte[lenght];
in.read(buffer);
result = EncodingUtils.getString(buffer, "Encoding.UTF_8");
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
方法2
public String read() {
InputStream in = context.getResources().openRawResource(R.raw.cc);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
try {
while ((len = in.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
// Log
String log = new String(outStream.toByteArray());
String[] row = log.split("\r
");
for (String element : row) {
String[] str = element.split("=");
for (int i = 0; i < str.length; i++) {
if (i + 1 < str.length) {
Log.i("TestRead", str[i]);
headlineValue.put(str[i].trim(), str[i + 1].trim());
}
}
}
Log.i("TestRead", log);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
byte[] data = outStream.toByteArray();
return new String(data);
}