求java程序..
答案:1 悬赏:20 手机版
解决时间 2021-02-27 06:52
- 提问者网友:咪咪
- 2021-02-26 06:34
求java程序..
最佳答案
- 五星知识达人网友:骨子里都是戏
- 2021-02-26 07:45
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public final class Second {
public static void main(String[] args) throws IOException {
//读字符流
String fileName = "c:/1.txt";
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
//写字符流
String fileNameres = "c:/2.txt";
FileWriter frres = new FileWriter(fileNameres);
BufferedWriter bwres = new BufferedWriter(frres);
//取出文本中所有行,并追加到StringBuffer中
StringBuffer sb=new StringBuffer("");
StringBuffer sbres=new StringBuffer("");
String nextLine;
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);
}
br.close();
fr.close();
char[] a=sb.toString().toCharArray();
for(int i=0;i int k=0;
for(int j=0;j if(a[i]==a[j]) k++;
}
if(sbres.toString().indexOf(String.valueOf(a[i]))<0){
String str=a[i]+":"+k+"次";
sbres.append(str+"\n");
System.out.println(str);
}
}
bwres.write(sbres.toString());
bwres.close();
frres.close();
}
}
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public final class Second {
public static void main(String[] args) throws IOException {
//读字符流
String fileName = "c:/1.txt";
FileReader fr = new FileReader(fileName);
BufferedReader br = new BufferedReader(fr);
//写字符流
String fileNameres = "c:/2.txt";
FileWriter frres = new FileWriter(fileNameres);
BufferedWriter bwres = new BufferedWriter(frres);
//取出文本中所有行,并追加到StringBuffer中
StringBuffer sb=new StringBuffer("");
StringBuffer sbres=new StringBuffer("");
String nextLine;
while ((nextLine = br.readLine()) != null) {
sb.append(nextLine);
}
br.close();
fr.close();
char[] a=sb.toString().toCharArray();
for(int i=0;i int k=0;
for(int j=0;j if(a[i]==a[j]) k++;
}
if(sbres.toString().indexOf(String.valueOf(a[i]))<0){
String str=a[i]+":"+k+"次";
sbres.append(str+"\n");
System.out.println(str);
}
}
bwres.write(sbres.toString());
bwres.close();
frres.close();
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯