关于流的编程题 从文件in.txt中度曲一篇英文文章存入到字符串数组中?按行删除空格,并对每行的单词按升序排序后存放回数组中,最后调用把结果输出到文件out.txt中。原始数据文件存放的格式是:每行的宽度均小于80个字符,含空格。希望给出完整代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.*;import java.util.*;public class CSDNT1 { private static void createFile(){ FileWriter fw=null; try{ fw=new FileWriter("out.txt"); String word="I am a boy"; for(int i=0;i<20;i++){ StringBuffer str=new StringBuffer(); for(int j=0;j<8;j++){ str.append(word); } fw.write(str.toString()+'\n'); } }catch(IOException e){ e.printStackTrace(); }finally{ try{ if(fw!=null) fw.close(); }catch(IOException e){ e.printStackTrace(); } } } private static void readFile(){ try{ FileReader fr=new FileReader("out.txt"); FileWriter fw=new FileWriter("out1.txt"); BufferedReader br=new BufferedReader(fr); String str; while((str=br.readLine())!=null){ String [] bstr=str.split(" "); StringBuffer line=new StringBuffer(); for(int i=0;i<bstr.length;i++){ char [] a=bstr[i].toCharArray(); Arrays.sort(a); bstr[i]=new String(a); line.append(bstr[i]); } fw.write(line+"\n"); } fw.close(); }catch(IOException e){ e.printStackTrace(); } } public static void main(String[] args) { createFile(); readFile(); }}创建了一个文件,打开,读入,按照你的要求写入 java语言聊天 关于远程访问数据库的问题 关于画线问题 如何Java获取硬盘的使用率? 关于JFrame的问题--有分 武汉的进:哪位知道武汉哪有卖最新版本的NetBeans或eclipse的中文教程 wwm1978请进,接分 谁可以提供我(Special_Edition_Using_Java)的中文版的下载 软件开发薪金调查! 我的java不太明白思想 很急的问题!请大家帮帮忙阿! 求教 Hibernater中双向 many-to-one关系的插入问题
import java.util.*;public class CSDNT1 { private static void createFile(){
FileWriter fw=null;
try{
fw=new FileWriter("out.txt");
String word="I am a boy";
for(int i=0;i<20;i++){
StringBuffer str=new StringBuffer();
for(int j=0;j<8;j++){
str.append(word);
}
fw.write(str.toString()+'\n');
}
}catch(IOException e){
e.printStackTrace();
}finally{
try{
if(fw!=null)
fw.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
private static void readFile(){
try{
FileReader fr=new FileReader("out.txt");
FileWriter fw=new FileWriter("out1.txt");
BufferedReader br=new BufferedReader(fr);
String str;
while((str=br.readLine())!=null){
String [] bstr=str.split(" ");
StringBuffer line=new StringBuffer();
for(int i=0;i<bstr.length;i++){
char [] a=bstr[i].toCharArray();
Arrays.sort(a);
bstr[i]=new String(a);
line.append(bstr[i]);
}
fw.write(line+"\n");
}
fw.close();
}catch(IOException e){
e.printStackTrace();
}
}
public static void main(String[] args) {
createFile();
readFile(); }}
创建了一个文件,打开,读入,按照你的要求写入