javaio编程题
1.将a.txt⽂件中的单词与b.txt⽂件中的单词交替合并到c.txt⽂件中,a.txt⽂件中的单词⽤回车符分隔,b.txt⽂件中⽤回车或空格进⾏分隔
class FileManager{
String[] words=null;
public FileManager(String filename,char[] seperator) throws IOException{
File file=new File(filename);
InputStream is=new FileInputStream(file);
byte[] b=new byte[(int)file.length()];
is.close();
String regx="";
if(seperator.length>1)
regx+=seperator[0]+"|"+seperator[1];
else
regx+=seperator[0];
words=new String(b).split(regx);
}
public static void Test7()throws IOException{
FileManager a=new FileManager("a.txt",new char[]{'\n'});
FileManager b=new FileManager("b.txt",new char[]{'\n',' '});
File file=new File("c.txt");
Writer w=new FileWriter(file);
int len1=a.words.length;
int len2=b.words.length;
int i;
if(len1>len2){
powermill编程真的比ug好吗
for(i=0;i<len2;i++){
w.write(a.words[i]+"\n");
w.write(b.words[i]+"\n");
}
while(i<len1){
w.write(a.words[i]+"\n");
i++;
}
}else{
for(i=0;i<len1;i++){
w.write(a.words[i]+"\n");
w.write(b.words[i]+"\n");
}
while(i<len2){
w.write(b.words[i]+"\n");
i++;
}
}
w.close();
Reader r=new FileReader(file);
char[] ch=new char[1024];
r.close();
System.out.println(new String(ch));
}
2.给定⼀个⽂件和⼀个字符串,判断⽂件是否包含该字符串,如果包含,请打印包含该字符串的⾏号及该⾏的全部内容
public static void Test8(String filename,String str) throws IOException{
int lineNum=0;
Map<Integer,String> map=new HashMap<Integer,String>();
File file=new File(filename);c语言最短代码写贪吃蛇
BufferedReader br=new BufferedReader(new FileReader(file));
adLine()!=null){
String adLine();
ains(str))
intellectualizemap.put(lineNum, tmp);
lineNum++;
}
br.close();
table与chart的区别
if(map.isEmpty())
System.out.println("该⽂件不包含该字符串");
else{
Iterator<Entry<Integer,String>> Set().iterator();
while(iterator.hasNext()){java虚拟机最新安卓版app
Entry<Integer,String> ();
System.out.println("⾏号:"+Key()+"该⾏内容:"+Value());      }
}
java经典上机编程题}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。