集册 Java实例教程 使用BufferedOutputStream将字节数组写入文件

使用BufferedOutputStream将字节数组写入文件

欢马劈雪     最近更新时间:2020-01-02 10:19:05

581
使用BufferedOutputStream将字节数组写入文件


import java.io.BufferedOutputStream;
/* 
*来 自
 时 代 J a v a - N o w J a v a . c o m
*/

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;


public class Main {


  public static void main(String[] args) {


    String strFileName = "C:/Folder/Demo";

    BufferedOutputStream bos = null;


    try {

      FileOutputStream fos = new FileOutputStream(new File(strFileName));

      bos = new BufferedOutputStream(fos);

      /* from 
      nowjava.com*/

      String str = "Example";


      bos.write(str.getBytes());


    } catch (FileNotFoundException fnfe) {

      System.out.println("Specified file not found" + fnfe);

    } catch (IOException ioe) {

      System.out.println("Error while writing file" + ioe);

    } finally {

      if (bos != null) {

        try {


      
展开阅读全文