最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android 讀取txt,按行讀取的實例講解

 更新時間:2018年05月08日 15:41:44   作者:Damionew  
今天小編就為大家分享一篇Android 讀取txt,按行讀取的實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

一個TXT 文件 對其進行讀取,并且每行都單個存儲讀取

public class MainActivity extends AppCompatActivity {
 private TextView textView,textView2,textView3;
 private Button click;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  textView = (TextView) findViewById(R.id.textView);
  textView2 = (TextView) findViewById(R.id.textView2);
  textView3 = (TextView) findViewById(R.id.textView3);
  String s1 = Txt().get(0);//從Map get (key = 0)的value
  String s2 = Txt().get(1);
  String s3 = Txt().get(2);
  textView.setText(s1);
  textView2.setText(s2);
  textView3.setText(s3);
 }
 public Map<Integer, String> Txt() {
  //將讀出來的一行行數(shù)據(jù)使用Map存儲
  String filePath = "/sdcard/sdl_log.txt";//手機上地址
  Map<Integer, String> map = new HashMap<Integer, String>();
  try {
   File file = new File(filePath);
   int count = 0;//初始化 key值
   if (file.isFile() && file.exists()) {  //文件存在的前提
    InputStreamReader isr = new InputStreamReader(new FileInputStream(file));
    BufferedReader br = new BufferedReader(isr);
    String lineTxt = null;
    while ((lineTxt = br.readLine()) != null) {  //
     if (!"".equals(lineTxt)) {
      String reds = lineTxt.split("\\+")[0];  //java 正則表達式
      map.put(count, reds);//依次放到map 0,value0;1,value2
      count++;
     }
    }
    isr.close();
    br.close();
   }else {
    Toast.makeText(getApplicationContext(),"can not find file",Toast.LENGTH_SHORT).show();//找不到文件情況下
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return map;
 }
}

以上這篇Android 讀取txt,按行讀取的實例講解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論

嘉荫县| 城固县| 上蔡县| 尚志市| 分宜县| 澄迈县| 富源县| 武隆县| 政和县| 三都| 武邑县| 冷水江市| 德保县| 凤庆县| 酉阳| 晋城| 娄烦县| 青海省| 喜德县| 饶阳县| 新晃| 恩平市| 沁水县| 鲁山县| 霍林郭勒市| 伽师县| 松江区| 红桥区| 开原市| 寻甸| 二连浩特市| 衡山县| 弥渡县| 古蔺县| 富宁县| 丁青县| 新竹市| 荃湾区| 乐平市| 上蔡县| 海淀区|