当前位置: 代码迷 >> J2SE >> File length()有关问题
  详细解决方案

File length()有关问题

热度:370   发布时间:2016-04-24 14:19:25.0
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();
}
}
  相关解决方案