java的一点小问题希望有人帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/24 12:22:49
编写一个程序来显示并复制文件内容,文件内容要转换为大写字符显示,文件名字及其内容自定。

复制的代码我做出来了就是不知道怎么转换。
public static void show1(){
File fi=new File("D:/f1.txt");
try {
FileInputStream input = new FileInputStream(fi);
FileOutputStream output=new FileOutputStream("D:/f2.txt");
byte[] i=new byte[1024];

while(input.read(i)!=-1){
output.write(i);
i=new byte[1024];
}
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}

}

public static void show1()throws IOException
{
BufferedReader reader=new BufferedReader(new FileReader("D:/f1.txt"));
BufferedWriter writer=new BufferedWriter(new FileWriter("D:/f2.txt"));
String s;
while((s=reader.readLine())!=null) //读
{
writer.write(s.toUpperCase()); //写入大写
}
reader.close();
writer.close();
}

这个我只能你一些思路:
1、用流的形式从文件中读出文件内容,最好把它赋给StringBuffer的对象(如:Cont)。
2、然后用Cont.toString().toUpperCase()转化成大写。
3、再把转化后的内容用流的形式写进文件,把原来内容替换了。