急求!!用java语言将一个文本文件a.txt中的内容写入一个新文件b.txt中

若写入的字符是小写字母,则需变换为大写后再写入文件中。急求!!!希望在今晚前给我写好,不胜感激!我现在只有20分没法给更多了,希望有人能帮帮我

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class QuestionOne {

// a文件路径 (输入文件)
private static final String INPUT_FILE_PATH = "c:/input.txt";

// b文件路径 (输出文件)
private static final String OUTPUT_FILE_PATH = "c:/output.txt";

/**
* 急求!!用java语言将一个文本文件a.txt中的内容写入一个新文件b.txt中 悬赏分:20 | 离问题结束还有 14 天 23 小时 |
* 提问者:我滴智商木下限 | 检举
* 若写入的字符是小写字母,则需变换为大写后再写入文件中。急求!!!希望在今晚前给我写好,不胜感激!我现在只有20分没法给更多了,希望有人能帮帮我
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
new FileInputStream(INPUT_FILE_PATH)));
PrintWriter writer = new PrintWriter(new File(OUTPUT_FILE_PATH));

String message = null; // 存储用户输入的字符串
try {
while ((message = reader.readLine()) != null) {
// 打印处理前的字符串
System.out.println("读入的字符串为:" + message);

// 小写转为大写的
message = message.toUpperCase();

// 打印处理后的字符串
System.out.println("处理后为:" + message);
writer.println(message);
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("出现异常,程序退出!");
}
writer.close();// 关闭
reader.close();
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-09
import java.io.*;

import com.sun.org.apache.bcel.internal.generic.NEW;
public class FileReaderUper {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis=new FileInputStream("G:\\a.txt");//注意文件路径
int len=fis.available();
byte[] txt=new byte[len];
fis.read(txt);//read file
String stxt=new String(txt);
byte[] btxt=stxt.toUpperCase().getBytes();
fos=new FileOutputStream("G:\\b.txt");
fos.write(btxt);//write file
fos.close();
fis.close();

} catch (Exception e) {
// TODO: handle exception
e.getMessage();
}

}

}
第2个回答  2011-03-10
我来晚了...楼上说的都对...io呗
相似回答