java.io.PrintWriter +print(cArray: char[]): void
java.io.PrintWriter +print(cArray: char[] ): void
我不知道如何写这行:+print(cArray: char[]): void
。我知道我想为我的家庭作业问题做什么,这本书解释得很糟糕,只是这条数组线。如果你想知道问题: 写一个程序创建一个名为 Excercise12_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
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();
}
}
这是将数组正确写入带空格的文本文件的方法。
我不知道如何写这行:+print(cArray: char[]): void
。我知道我想为我的家庭作业问题做什么,这本书解释得很糟糕,只是这条数组线。如果你想知道问题: 写一个程序创建一个名为 Excercise12_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
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();
}
}
这是将数组正确写入带空格的文本文件的方法。