没问题啊,可以运行呢。虽然用int不太好就是了。
- import java.io.File;
- import java.util.Scanner;
- public class FileDemo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String filePath = scanner.nextLine();
- File file = new File(filePath);
- System.out.println(getFileSize(file));
- }
- public static int getFileSize(File f) {
- long l = f.length();
- return (int) l;
- }
- }
复制代码
|
|