FileInputStream fis = new FileInputStream("文件路径");
byte[] buffer = new byte[1024];
int bytesRead = fis.read(buffer);
while (bytesRead != -1) {
// 处理读取到的数据
// ...
// 继续读取文件内容
bytesRead = fis.read(buffer);
}
fis.close();
import java.io.FileInputStream;
import java.io.IOException;
public class ReadFileExample {
public static void main(String[] args) {
FileInputStream fis = null;
try {
fis = new FileInputStream("文件路径");
byte[] buffer = new byte[1024];
int bytesRead = fis.read(buffer);
while (bytesRead != -1) {
// 处理读取到的数据
// ...
// 继续读取文件内容
bytesRead = fis.read(buffer);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com