国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > Android > 正文

Android 讀取txt,按行讀取的實(shí)例講解

2019-10-22 18:11:52
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

一個(gè)TXT 文件 對(duì)其進(jìn)行讀取,并且每行都單個(gè)存儲(chǔ)讀取

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() {  //將讀出來(lái)的一行行數(shù)據(jù)使用Map存儲(chǔ)  String filePath = "/sdcard/sdl_log.txt";//手機(jī)上地址  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 正則表達(dá)式      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

Android,按行,讀取,txt

以上這篇Android 讀取txt,按行讀取的實(shí)例講解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到Android開(kāi)發(fā)頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 日土县| 星子县| 镇坪县| 南木林县| 旅游| 淳化县| 济阳县| 海兴县| 教育| 哈巴河县| 左权县| 海淀区| 耿马| 马尔康县| 雅安市| 太仆寺旗| 木兰县| 漾濞| 泌阳县| 承德县| 赤水市| 精河县| 运城市| 兴仁县| 阜新市| 昌江| 安泽县| 牡丹江市| 朝阳县| 通化县| 九龙城区| 刚察县| 江达县| 名山县| 泗洪县| 察雅县| 彰化市| 句容市| 即墨市| 龙里县| 博白县|