使用输出流将数据添加到特定文件

发布于 2025-01-07 21:51:10 字数 199 浏览 0 评论 0原文

String data="this we want append in that file";
byte[] getbyte = data.getBytes();
outputstream.write(getbyte);
outputstream.flush();

通过使用这些代码,我尝试将数据写入特定文件,但数据未添加到该文件中

String data="this we want append in that file";
byte[] getbyte = data.getBytes();
outputstream.write(getbyte);
outputstream.flush();

by using these code i m trying to write data in particlar file but data is not get added it that file

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灵芸 2025-01-14 21:51:10

导入java.io.*;

公共类 WriteFileExample {

公共静态 void main(String[] args) {

String strFilePath = "d:/FileIO.txt";

 try
 {
  FileOutputStream fos = new FileOutputStream(strFilePath);
  String strContent = "Write File using Java FileOutputStream example !";

  /*
   * To write byte array to a file, use
   * void write(byte[] bArray) method of Java FileOutputStream class.
   *
   * This method writes given byte array to a file.
   */

   fos.write(strContent.getBytes());

  /*
   * Close FileOutputStream using,
   * void close() method of Java FileOutputStream class.
   *
   */

   fos.close();

 }
 catch(FileNotFoundException ex)
 {
  System.out.println("FileNotFoundException : " + ex);
 }
 catch(IOException ioe)
 {
  System.out.println("IOException : " + ioe);
 }

}
}

import java.io.*;

public class WriteFileExample {

public static void main(String[] args) {

String strFilePath = "d:/FileIO.txt";

 try
 {
  FileOutputStream fos = new FileOutputStream(strFilePath);
  String strContent = "Write File using Java FileOutputStream example !";

  /*
   * To write byte array to a file, use
   * void write(byte[] bArray) method of Java FileOutputStream class.
   *
   * This method writes given byte array to a file.
   */

   fos.write(strContent.getBytes());

  /*
   * Close FileOutputStream using,
   * void close() method of Java FileOutputStream class.
   *
   */

   fos.close();

 }
 catch(FileNotFoundException ex)
 {
  System.out.println("FileNotFoundException : " + ex);
 }
 catch(IOException ioe)
 {
  System.out.println("IOException : " + ioe);
 }

}
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文