добавить данные в определенный файл с помощью outputtream - PullRequest
1 голос
/ 23 февраля 2012
String data="this we want append in that file";
byte[] getbyte = data.getBytes();
outputstream.write(getbyte);
outputstream.flush();

с помощью этого кода я пытаюсь записать данные в конкретный файл, но данные не добавляются в этот файл

1 Ответ

0 голосов
/ 23 февраля 2012

импорт java.io. *;

открытый класс WriteFileExample {

public static void main (аргументы String []) {

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

} }

...