java - 当我尝试写入文件时,为什么 Eclipse IDE 会给出终止错误?

标签 java eclipse file io

import java.io.*;

public class FileWriterDemo {

/**
 * @param args
 */
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub

    String source = "Now is the time for all good men\n" +
                    " to come to aid of their country\n" +
                    " and pay their due taxes";

    char buffer[] = new char[source.length()];
    source.getChars(0, source.length(), buffer, 0);

    FileWriter f0 = new FileWriter("file1.txt");
    FileWriter f1 = new FileWriter("file2.txt");
    FileWriter f2 = new FileWriter("file3.txt");

    try{
        for(int i =0; i<buffer.length; i+=2){
            f0.write(buffer[i]);
        }

        f1.write(buffer);
        f2.write(buffer, buffer.length-buffer.length/4, buffer.length/4);

    }catch (IOException e){
        System.out.println("An I/O Error occured.");
    }
}

}

这是我写的程序。我从一本书上复制了这个程序,但我的 IDE (Eclipse) 不断给我消息。当我尝试使用 FileOutputStream 类对象创建文件并写入文件时,遇到了同样的问题。

这是一张图片

最佳答案

这只是意味着程序已完成,并且在您的情况下可能成功,因为它没有在控制台上打印任何内容。

只需检查file1.txt、file2.txt和file3.txt的内容即可查看程序是否成功

关于java - 当我尝试写入文件时,为什么 Eclipse IDE 会给出终止错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10984179/

相关文章:

java - 单元测试-Mockito和Butterknife-如何 mock

java - 插入更新或删除后如何刷新JTable

java - JSSC 串行接口(interface)上​​的 UnsatsifiedLinkError(处理)

c++ - 在删除文件之前检查文件是否仍在被另一个进程使用(c、c++、linux)

java - 使用 spring 和 Hibernate 的基本 CRUD 应用程序

java - 缩小图像按钮中的位图以避免内存不足

java - <%@ taglib 前缀 ="c"uri ="http://java.sun.com/jsp/jSTL/core"%> Eclipse photon jdk 10 Tomcat 9

java - 组合字符串 - 相同字符的运行保持在一起

Java如何通过分隔符字符串将文本文件分隔为文件

PHP,在json中索引mysql ID。这值得么?