为什么用BufferedWriter不能将字符串写入文件?
生成了空的文件!try{//:用字符流读取BufferedReaderbReader=newBufferedReader(newInputStreamReader(new...
生成了空的文件!
try {
//:用字符流读取
BufferedReader bReader=new BufferedReader(
new InputStreamReader(
new DataInputStream(
new FileInputStream(
new File("c:/a.txt")))));
//:用字符流输出
BufferedWriter bWriter=new BufferedWriter(
new OutputStreamWriter(
new BufferedOutputStream(
new DataOutputStream(
new FileOutputStream(
new File("c:/b.txt"))))));
String sssString=null;
char [] charstring=new char[512];
int length=0;
try {
while(null!=(sssString=bReader.readLine())){
bWriter.write(sssString);
}
// while(-1!=(length=bReader.read(charstring))){
// String ssString=new String(charstring, 0, length);
// //bWriter.write(charstring, 0, length);
// bWriter.write(ssString);
// }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} 展开
try {
//:用字符流读取
BufferedReader bReader=new BufferedReader(
new InputStreamReader(
new DataInputStream(
new FileInputStream(
new File("c:/a.txt")))));
//:用字符流输出
BufferedWriter bWriter=new BufferedWriter(
new OutputStreamWriter(
new BufferedOutputStream(
new DataOutputStream(
new FileOutputStream(
new File("c:/b.txt"))))));
String sssString=null;
char [] charstring=new char[512];
int length=0;
try {
while(null!=(sssString=bReader.readLine())){
bWriter.write(sssString);
}
// while(-1!=(length=bReader.read(charstring))){
// String ssString=new String(charstring, 0, length);
// //bWriter.write(charstring, 0, length);
// bWriter.write(ssString);
// }
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询