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

Android開發(fā)實現(xiàn)Files文件讀取解析功能示例

 更新時間:2017年09月08日 10:17:42   作者:ITzhongzi  
這篇文章主要介紹了Android開發(fā)實現(xiàn)Files文件讀取解析功能,結(jié)合實例形式分析了Android針對txt文本文件的讀取、保存功能實現(xiàn)方法與布局操作技巧,需要的朋友可以參考下

本文實例講述了Android開發(fā)實現(xiàn)Files文件讀取解析功能。分享給大家供大家參考,具體如下:

package com.example.file;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
  EditText edt;
  Button btn;
  TextView tv;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    edt = (EditText) findViewById(R.id.editText);
    btn = (Button) findViewById(R.id.button);
    tv = (TextView) findViewById(R.id.textView);
    btn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
        WriteFiles(edt.getText().toString());
        tv.setText(readFiles());
      }
    });
  }
  //保存文件內(nèi)容
  public void WriteFiles(String content){
    try {
      FileOutputStream fos = openFileOutput("a.txt",MODE_PRIVATE);
      fos.write(content.getBytes());
      fos.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  //讀取文件
  public String readFiles(){
    String content = null;
    try {
      FileInputStream fis = openFileInput("a.txt");
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      byte[]buffer = new byte[1024];
      int len = 0;
      while ((len = fis.read(buffer))!=-1)
      {
        baos.write(buffer,0,len);
      }
      content = baos.toString();
      fis.close();;
      baos.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return content;
  }
}

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.file.MainActivity">
  <EditText
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:id="@+id/editText"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />
  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_below="@+id/editText"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="90dp" />
  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_below="@+id/button"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
</RelativeLayout>

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android視圖View技巧總結(jié)》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

  • Android開發(fā)實現(xiàn)生成excel的方法詳解

    Android開發(fā)實現(xiàn)生成excel的方法詳解

    這篇文章主要介紹了Android開發(fā)實現(xiàn)生成excel的方法,結(jié)合實例形式詳細(xì)分析了Android生成Excel的具體步驟與存儲、導(dǎo)入、添加等相關(guān)操作技巧,需要的朋友可以參考下
    2017-10-10
  • Android ViewPagerIndicator詳解及實例代碼

    Android ViewPagerIndicator詳解及實例代碼

    這篇文章主要介紹了Android ViewPagerIndicator詳解及實例代碼的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • flutter BottomAppBar實現(xiàn)不規(guī)則底部導(dǎo)航欄

    flutter BottomAppBar實現(xiàn)不規(guī)則底部導(dǎo)航欄

    這篇文章主要為大家詳細(xì)介紹了flutter BottomAppBar實現(xiàn)不規(guī)則底部導(dǎo)航欄,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • 詳解四種主要的Android依賴管理方式

    詳解四種主要的Android依賴管理方式

    Android應(yīng)用開發(fā)涉及大量的依賴庫和第三方組件,因此有效地管理這些依賴關(guān)系至關(guān)重要,本文將介紹四種主要的Android依賴管理方式,分析它們的優(yōu)點、缺點以及最佳實踐,需要的朋友可以參考下
    2023-09-09
  • 基于Android SQLite的使用介紹

    基于Android SQLite的使用介紹

    本篇文章小編為大家介紹,基于Android SQLite的使用說明,需要的朋友參考下
    2013-04-04
  • Android中TabLayout+ViewPager實現(xiàn)tab和頁面聯(lián)動效果

    Android中TabLayout+ViewPager實現(xiàn)tab和頁面聯(lián)動效果

    本篇文章主要介紹了Android中TabLayout+ViewPager實現(xiàn)tab和頁面聯(lián)動效果,具有一定的參考價值,有興趣的可以了解一下
    2017-06-06
  • Android自定義View的一些獨家技巧

    Android自定義View的一些獨家技巧

    很多人把自定義View想得復(fù)雜了,以為有多高深,主要還是沒有實踐過,下面這篇文章主要給大家介紹了關(guān)于Android自定義View的一些獨家技巧,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • Android控件系列之ImageView使用方法

    Android控件系列之ImageView使用方法

    Android控件系列之ImageView使用方法,學(xué)習(xí)android的朋友可以參考下
    2012-11-11
  • Android仿直播特效之點贊飄心效果

    Android仿直播特效之點贊飄心效果

    這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)點贊飄心效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-03-03
  • Android N多窗口支持

    Android N多窗口支持

    Android N 可以同時顯示多個應(yīng)用窗口。在手機上,兩個應(yīng)用可以在“分屏”模式中左右并排或上下并排顯示。本文將對此介紹。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-05-05

最新評論

滦南县| 华亭县| 怀宁县| 台江县| 噶尔县| 平远县| 安平县| 青川县| 怀柔区| 湖北省| 峨边| 翁源县| 天气| 丰城市| 西安市| 萝北县| 增城市| 郧西县| 铜山县| 红桥区| 韩城市| 大理市| 温宿县| 通州市| 安新县| 老河口市| 扶风县| 青神县| 定陶县| 五莲县| 威远县| 滦南县| 东海县| 遵义市| 江都市| 永寿县| 石楼县| 杂多县| 湖北省| 清涧县| 普兰店市|