zoukankan      html  css  js  c++  java
  • 字符 单词数 行数

    布局代码:

    <EditText

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:id="@+id/et_writ"

    android:singleLine="false"

    android:hint="请输入数据"

    android:imeOptions="actionDone"

    />// 监听回车键

    <Button

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:id="@+id/btn"

    android:text="开始解析数据"

    android:textSize="20dp"

    />

    <LinearLayout

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:orientation="vertical"> <TextView

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:id="@+id/tv_v" android:text="显示数据"

    />

    核心功能代码

    public void onClick(View v) {

    int charnumber = 0 ; //字符

    int words = 0; //单词

    int linenumber = 0; //行数

    String filename=editText.getText().toString();

    try {

    File file = new File(Environment.getExternalStorageDirectory().getCanonicalPath() + "/"+filename+".txt");

    FileInputStream isr=new FileInputStream(file);

    BufferedReader br = new BufferedReader(new InputStreamReader(isr));

    while( br.read()!= -1){ String s = br.readLine();

    charnumber+=s.length();

    words +=s.split(" ").length;

    linenumber ++;

    }

    isr.close();

    textView.setText("字符数:"+charnumber+" 单词数:"+words+"行 数:"+linenumber);

    }

    catch (IOException e) { e.printStackTrace();

    }

    }

  • 相关阅读:
    HutchTab
    configbody tcl tk
    initial class tcl tk
    ::dcss
    StatusBar
    read url c#
    new tab addin
    extraDevice
    Android平台开发WIFI function portingWIFI功能移植
    如何设置Android系统中的BT2.1 device到SSP的DEBUG模式
  • 原文地址:https://www.cnblogs.com/chenbaiwan/p/6629427.html
Copyright © 2011-2022 走看看