java 字节流 多个文件写入一个文件 为什么前面写入的内容会被覆盖了
3个回答
展开全部
package javaTest;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Test
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new FileReader("D:\\test.txt"));
StringBuffer sb = new StringBuffer();
String lineContent = null ;
while( (lineContent = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer( lineContent," " );
for( int t=0; st.hasMoreElements() ; t++){
String word = (String) st.nextElement();
sb.append( word );
if( t== 0){
sb.append(" ");
}
if( t==1){
sb.append(" ");
}
}
sb.append("\n");
}
PrintWriter pw = new PrintWriter("D:\\test1.txt");
pw.write(sb.toString());
br.close();
pw.close();
}
}
具体的自己改改吧。
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Test
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new FileReader("D:\\test.txt"));
StringBuffer sb = new StringBuffer();
String lineContent = null ;
while( (lineContent = br.readLine()) != null)
{
StringTokenizer st = new StringTokenizer( lineContent," " );
for( int t=0; st.hasMoreElements() ; t++){
String word = (String) st.nextElement();
sb.append( word );
if( t== 0){
sb.append(" ");
}
if( t==1){
sb.append(" ");
}
}
sb.append("\n");
}
PrintWriter pw = new PrintWriter("D:\\test1.txt");
pw.write(sb.toString());
br.close();
pw.close();
}
}
具体的自己改改吧。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询