集册 Java实例教程 确定写入DataOutputStream的字节数

确定写入DataOutputStream的字节数

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

426
确定写入DataOutputStream的字节数
/** 来 自 n o w j a v a . c o m**/

import java.io.DataOutputStream;

import java.io.FileOutputStream;

import java.io.IOException;

 

public class Main {

 

  public static void main(String[] args) {

   

    String strFilePath = "C://Folder//NumberOfBytes.txt";

   

    try

    {

      //create FileOutputStream object

      FileOutputStream fos = new FileOutputStream(strFilePath);

     

       DataOutputStream dos = new DataOutputStream(fos);

     

       String str = "Example to show number of bytes written to stream";

       dos.writeBytes(str);

     

        int bytesWritten = dos.size();/** from 时 代 J a v a**/

        System.out.println("Total " + bytesWritten + 
展开阅读全文