请优化以下代码

public static void main(String[] args) throws IOException {
    File file = new File("some file path");
    List list1 = new ArrayList();
    FileInputStream fileInputStream = new FileInputStream(file);
    byte[] bytes = new byte[1024];
    int i = fileInputStream.read(bytes);
    if(i > 0) {
        do {
            i = fileInputStream.read(bytes);
            String s = new String(bytes, 0 , i);
            list1.add(s);
        } while(i != -1);
    }
    i = fileInputStream.read(bytes);
    String start = new String(bytes, 0, i);
    list1.add(start);
    for (int i1 = 0; i1 < list1.size(); i1++) {
        String s = (String) list1.get(i1);
        if(s.contains("1")) {
            s = s.replace("1", "a");
        } else if(s.contains("2")) {
            s = s.replace("2", "b");
        } else if(s.contains("3")) {
            s = s.replace("3", "c");
        } else if(s.contains("4")) {
            s = s.replace("4", "d");
        }
        list1.remove(i1);
        list1.add(i1, s);
    }
    FileOutputStream fos = new FileOutputStream(file);
    for (Object o : list1) {
        fos.write(o.toString().getBytes());
    }
}
全部评论
马住慢慢看
点赞 回复 分享
发布于 2023-03-04 12:15 河北
这不致远互联吗
点赞 回复 分享
发布于 2023-02-28 19:37 黑龙江

相关推荐

头像
2025-12-27 13:01
三峡大学 C++
点赞 评论 收藏
分享
白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务