/**
* @Description: 对文件进行读操作
* @author: 李世康
* @date: 2021年06月17日 9:30
*/
public class IoText {
public static void main(String[] args) {
c();
}
private static void c() {
InputStream inputStream=null;
try {
inputStream =new FileInputStream("D:"+ File.separator+"IoText.java");
byte [] bytes=new byte[10];
StringBuffer stringBuffer=new StringBuffer();
while (inputStream.read(bytes) != -1) {
String str=new String(bytes);
stringBuffer.append(str);
}
System.out.println(stringBuffer);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (inputStream != null){
inputStream.close();
}
}catch (IOException e) {
e.printStackTrace();
}
}
}
}
通过InputStream对文件进行读取操作
最新推荐文章于 2024-05-03 17:32:28 发布