File length()问题

zkheartboy 2007-07-29 11:28:59
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啊?
...全文
724 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangCK 2007-07-29
  • 打赏
  • 举报
回复
/*
* 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();
}
}
zkheartboy 2007-07-29
  • 打赏
  • 举报
回复
里面有东西,
已经搞定了,谢谢了。
原来是要把fos关闭了才可以。
zapdos 2007-07-29
  • 打赏
  • 举报
回复
那个是文件大小的 意思,应该是你的D:\\bbb.txt里面没有东西

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧