怎样把一个字符串写入文件中? 马上结帖

kingeyetiger 2003-03-27 04:29:22
我用:
fileoutputstream.write(line, ?, ?);
编译出现:
symbol : method write (java.lang.String,int,int)
location:class java.io.FileOutputStream fileoutputstream.write(line,0,1);

后两个参数是什么意思?
...全文
177 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zxhong 2003-03-27
<%
StringBuffer txtConcent = new StringBuffer() ;
String sSrcName="c:\\test.txt";
txtConcent.append("abc") ;
try
{
java.io.PrintWriter pw = new java.io.PrintWriter(new java.io.FileWriter(sSrcName, true), true);
pw.println(txtConcent.toString());
}
catch (Exception e)
{

}

%>
回复
kingeyetiger 2003-03-27
String 类型的一个变量怎么放进文件里呢?
回复
vcvj 2003-03-27
偏移位字节开始与b[10]的话偏移3就从b[3]开始
共写出多少长度

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
回复
gzwrj 2003-03-27
public static void writeFile(String str, String filename) throws Exception
{
// Open a writer to the file, then write the string.
BufferedWriter bwriter;//writer to the file
String fullfilepath;//path for the output file
try
{
bwriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename)));
bwriter.write(str);
bwriter.flush();
bwriter.close();
}//try
catch(Exception e)
{
throw e;
}//catch
回复
Hackevin 2003-03-27
public void write(byte[] b,
int off,
int len)
throws IOException

Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
回复
kofwr 2003-03-27
写字符串直接套PrintWriter,套Writer的子类都可以...
回复
geyf 2003-03-27
write(byte[] b, int off, int len)
Writes len bytes from the specified byte array starting at offset off to this file output stream.
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2003-03-27 04:29
社区公告
暂无公告