首页 > 编程知识 正文

肾单位模型制作方法,计数单位的表示方法

时间:2023-05-06 05:26:31 阅读:250828 作者:1144

Java File length()方法

java.io.File.length() 返回此抽象路径名定义的文件的长度。如果此路径名定义了一个目录返回值未指定。

1 语法

public long length()

2 参数

3 返回值

该方法返回表示此抽象路径名的文件的长度,以字节为单位。

4 示例

package com.yiidian;

/**

* 一点教程网: http://www.yiidian.com

*/

/**

* java.io.File.length()方法的例子

*/

import java.io.File;

public class Demo {

public static void main(String[] args) {

File f = null;

String path;

long len;

boolean bool = false;

try {

// create new file

f = new File("d:/test.txt");

// true if the file path is a file, else false

bool = f.exists();

// if path exists

if(bool) {

// returns the length in bytes

len = f.length();

// path

path = f.getPath();

// print

System.out.print(path+" file length: "+len);

}

} catch(Exception e) {

// if any error occurs

e.printStackTrace();

}

}

}

假设test.txt文件内容如下:

ABCDE

输出结果为:

d:test.txt file length: 5

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。