请优化以下代码

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 黑龙江

相关推荐

08-11 17:48
辽宁大学 财务
投秋招已经快两周,每天就是投投投到厌倦然后躺床上刷痘印越刷越焦虑
驼瑞驰_招募评论官版...:你把牛客放中间,那你必得offer的
点赞 评论 收藏
分享
08-13 13:54
门头沟学院 Java
被卡学历了简历挂,绷不住了...
去哪儿旅行呢:估计看你有字节实习也不会去
投递4399游戏等公司10个岗位
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

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