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

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);

后两个参数是什么意思?
...全文
227 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
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.

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧