日期:2014-05-20  浏览次数:20685 次

File length()问题
File   file   =   new   File( "D:\\bbb.txt ");
file.createNewFile();
FileOutputStream   fos   =   new   FileOutputStream(file);
for(int   i= 'a ';i <= 'z ';i++)
{
fos.write(i);
}

FileInputStream   fis   =   new   FileInputStream(file);
System.out.println(file.length());

怎么length()打印出来是0啊?

------解决方案--------------------
/*
* Main.java
*
* Created on 2007年7月29日, 下午10:49
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

import java.io.*;

//package nb;

/**
*
* @author Administrator
*/

public class Main{

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
File file = new File( "D:\\bbb.txt ");
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
for(int i= 'a ';i <= 'z ';i++){
fos.write(i);
}
fos.close(); //关闭一下.

FileInputStream fis = new FileInputStream(file);
System.out.println(file.length());
fis.close();
}
}