热门

最新

红包

立Flag

投票

同城

我的

发布
weixin_65308520
一门一三
3 年前
trueweixin_65308520

使用read()方法取一个字节数据

package Reading;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/* 读取文件中的数据,使用read方法
*/
public class Reading { public static void main(String[] args) { FileInputStream fos = null; try { fos = new FileInputStream("fors.txt"); } catch (FileNotFoundException e) { e.printStackTrace(); } try { int by; while((by = fos.read())!=-1){ System.out.print((char)by); } } catch (IOException e) { e.printStackTrace(); } try { fos.close(); } catch (IOException e) { e.printStackTrace(); } }
}

代码片段分享
CSDN App 扫码分享
分享
评论
2
打赏
  • 复制链接
  • 举报
下一条:
感谢
立即登录