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();

    }

    }

  • 相关阅读:
    Dijkstra模版
    Trie树|字典树的简介及实现
    hdoj_2066一个人的旅行
    什么是java对象的强、软、弱和虚引用
    cxf调用客户端的方法
    CXF几种客户端调用性能
    csf几种调用的性能考虑
    cxf生成服务器端
    CXF在jdk1.6中运行异常解决
    CXF几种客户端调用性能
  • 原文地址:https://www.cnblogs.com/chenbaiwan/p/6629427.html
Copyright © 2011-2022 走看看