try{
FileOutputStream fos = new FileOutputStream("e.txt");
String s="fjkdsl";
fos.write(s.getBytes());
fos.close();
}catch(IOException e){
}
FileOutputStream fos = new FileOutputStream("e.txt");
String s="fjkdsl";
fos.write(s.getBytes());
fos.close();
}catch(IOException e){
}
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("e.txt")));
String s="fjkdsl";
out.write(s,0,s.length());
out.close();
}catch(IOException e){
}
import java.io.IOException;
public class StrToFile
{
public static void main(String[] args)
{
String str="This is a string.";
try
{
FileOutputStream fout=new FileOutputStream("strtofile.txt");
fout.write(str.getBytes());
fout.close();
}
catch(IOException e){System.out.println(e.getMessage());}
}
}
OutputStream可以直接传给PrintWriter(BufferedWriter不能接收),如:
PrintWriter out
= new PrintWriter(new BufferedOutputStream(new FileOutputStream("foo.out")));
或者用OutputStreamWriter来将OutputStream转化为Wrtier.这时就可以用BufferedWriter了。
API documents中写的很清楚了。
s=addf,fdfd,fdsfdf
b=ddff,fdfddf,weewew
我想把他们写到文件qq.txt中去,串s在第一行,串b在第二行,
但是会出现串b把串c覆盖了的问题
请问怎么不覆盖的把他们按上述要求考到文件中去呢?