Java如何使用固定字节数读取文件呢?
下文笔者讲述java代码读取固定字节数的方法及示例分享,如下所示
使用 FileInputStream 读取文件 使用FileWriter写入文件
public class TestClass{ public static void main(String[] args){ byte[] buffer = new byte[100]; try{ FileInputStream f = new FileInputStream("test.txt"); FileWriter writer = new FileWriter("copy_test.txt"); int b; while ((b=f.read(buffer)) != -1 ) writer.write(new String(buffer)); writer.close(); } catch(Exception e){ e.printStackTrace(); } } }
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。