java.io.PrintWriter+;打印(cArray:char[]):无效

java.io.PrintWriter+;打印(cArray:char[]):无效,java,arrays,exception,printing,Java,Arrays,Exception,Printing,我不知道怎么写这行:+print(cArray:char[]):void。我知道我想做什么来解决我的家庭作业问题,这本书对这一行的解释非常糟糕。如果您想知道问题:编写一个程序来创建一个名为exercise12_15.tx的文件(如果它不存在)。使用测试I/O将随机创建的100个整数写入文件。整数在文件中用空格分隔。从文件中读回数据并按递增顺序显示数据 package WriteReadData; import java.util.*; public class WriteReadData {

我不知道怎么写这行:
+print(cArray:char[]):void
。我知道我想做什么来解决我的家庭作业问题,这本书对这一行的解释非常糟糕。如果您想知道问题:编写一个程序来创建一个名为
exercise12_15.tx的文件(如果它不存在)。使用测试I/O将随机创建的100个整数写入文件。整数在文件中用空格分隔。从文件中读回数据并按递增顺序显示数据

package WriteReadData;

import java.util.*;
public class WriteReadData {

    public static void main(String[] args) throws Exception
    {
        java.io.File file = new java.io.File("Excercise12_15.txt");
        final int SIZE = 100;
        int [] emptyArray = new int[SIZE];

        if ( file.exists())
        {
            System.out.print("File exists");
            System.exit(0);
        }//end if 

        try 
        {
            java.io.PrintWriter output = new java.io.PrintWriter(file);

            for (int i = 1; i < SIZE; i++)
            {
            emptyArray[i] = (int)(Math.random() * 100);
            output.print(emptyArray: int[]): void 
            }//end for 

        }//end try 
        catch 
        {
            output.close();
        }//end catch 
    }//end main 
}//end class
package writeradata;
导入java.util.*;
公共类WriteReadData{
公共静态void main(字符串[]args)引发异常
{
java.io.File File=new java.io.File(“exercise12_15.txt”);
最终整数大小=100;
int[]emptyArray=新int[SIZE];
if(file.exists())
{
System.out.print(“文件存在”);
系统出口(0);
}//如果结束
尝试
{
java.io.PrintWriter输出=新的java.io.PrintWriter(文件);
对于(int i=1;i
java.io.File File=new java.io.File(“C:/Users/someUser/Desktop/exercise12_15.txt”);
最终整数大小=100;
int[]emptyArray=新int[SIZE];
if(file.exists())
{
System.out.print(“文件存在”);
系统出口(0);
}//如果结束
//将输出变量放在这里,以便可以在catch和finally块中看到它。
java.io.PrintWriter输出=null;
尝试
{
输出=新的java.io.PrintWriter(文件);
对于(int i=1;i

这是如何正确地将数组写入带有空格的文本文件。

此程序还没有完成。当然,我只需要回答我的问题,使其指向正确的方向。将数组打印到文本文件时遇到问题?不要将output.close()放在catch block中谢谢您的帮助。但是为什么这本书把这个例子列为:+print(cArray:char[]):void?(Java第10版简介,Daniel Liang)。@Doug099-非常抱歉,我没有那本书。可能是一个错误,检查官方网站的任何错误。
java.io.File file = new java.io.File("C:/Users/someUser/Desktop/Excercise12_15.txt");
    final int SIZE = 100;
    int [] emptyArray = new int[SIZE];

    if ( file.exists())
    {
        System.out.print("File exists");
        System.exit(0);
    }//end if 

//Place your output variable up here, so that it could be seen in the catch and finally block.

    java.io.PrintWriter output = null;
    try 
    {
        output = new java.io.PrintWriter(file);

        for (int i = 1; i < SIZE; i++)
        {
            emptyArray[i] = (int)(Math.random() * 100);
            //Your issuse was here, you didn't write the array to the file correctly
            output.print(emptyArray[i] + " "); 
        }//end for 

    }//end try 
    catch (Exception ex)
    {
        System.out.println(ex.getMessage());
    }//end catch
    finally{
        //Don't place the close in the catch block, do it in the finally, because it always
        //executes even when a catch happens.
         output.close();
    }

}