update:demo5

This commit is contained in:
dichgrem
2025-12-05 14:33:25 +08:00
parent 5832b4fe9d
commit 43c6b58317
5 changed files with 103 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
package com.study.demo5;
import java.io.*;
public class FileStat {
public long countBytes(String filePath) {
long totalBytes = 0;
try (FileInputStream fis = new FileInputStream(filePath)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
totalBytes += bytesRead;
}
} catch (IOException e) {
System.err.println("文件读取失败: " + e.getMessage());
return -1;
}
return totalBytes;
}
}