代码拉取完成,页面将自动刷新
package com.kong.base;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class BaseCount {
private int c = -1;
private int w = -1;
private int l = -1;
private File file;
public int countChar(String file) throws IOException {
this.file = new File(file);
FileInputStream fip = new FileInputStream(this.file);
InputStreamReader reader = new InputStreamReader(fip);
StringBuffer sBuffer = new StringBuffer();
while (reader.ready()) {
sBuffer.append((char) reader.read());
}
c = sBuffer.length();
reader.close();
fip.close();
return c;
}
public int countLine(String file) throws IOException {
this.file = new File(file);
FileInputStream fip = new FileInputStream(this.file);
InputStreamReader reader = new InputStreamReader(fip);
StringBuffer sBuffer = new StringBuffer();
while (reader.ready()) {
sBuffer.append((char) reader.read());
}
String str = sBuffer.toString();
char[] ch = str.toCharArray();
l = 0;
for (char c : ch) {
if (c == '\n') {
l++;
}
}
reader.close();
fip.close();
return l;
}
public int countWord(String file) throws IOException {
this.file = new File(file);
FileInputStream fip = new FileInputStream(this.file);
InputStreamReader reader = new InputStreamReader(fip);
StringBuffer sBuffer = new StringBuffer();
while (reader.ready()) {
sBuffer.append((char) reader.read());
}
String str = sBuffer.toString();
char[] ch = str.toCharArray();
w = 0;
for (char c : ch) {
if (c == '\n' || c == '\r' || c == ' ' || c == ',' || c == ';' || c=='.') {
w++;
}
}
reader.close();
fip.close();
return w;
}
public void outputFile(String file) throws IOException {
File f = new File(file);
FileOutputStream fop = new FileOutputStream(f);
OutputStreamWriter writer = new OutputStreamWriter(fop);
if (c > 0) {
writer.append(this.file.getName() + ",字符数:" + c+"\r\n");
}
if (w > 0) {
writer.append(this.file.getName() + ",单词数:" + w+"\r\n");
}
if (l > 0) {
writer.append(this.file.getName() + ",行数:" + l+"\r\n");
}
writer.close();
fop.close();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。