- Android
- 2012-06-06
assetsフォルダーに格納したテキストファイルを読み込みます。
InputStream inputStream = null; BufferedReader reader = null; try { inputStream = getResources().getAssets().open("ファイル名"); reader = new BufferedReader( new InputStreamReader(inputStream)); String line; StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { Log.v("reader", line); if(line != ""){ sb.append(line); } } String str = sb.toString(); Toast.makeText(this, str, Toast.LENGTH_LONG).show(); } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { try { reader.close(); inputStream.close(); } catch (IOException e) { e.printStackTrace(); } }
7,194 views