【发布时间】:2014-11-25 06:34:34
【问题描述】:
这个项目应该有 3 个独立的主类。 它输入一个按字母顺序排序的国家列表文件,它输出一个未排序的文件,其中行随机重新排列。
我的第一个主课是这样的:
package assignment3;
import java.io.PrintWriter;
import java.io.File;
import java.util.Scanner;
public class Assignment3 {`
public static void main(String[] args) throws Exception{
Scanner stdIn = new Scanner(new File("C:/Users/Vicki/Desktop/CountrySortedFormat.txt"));
PrintWriter out = new PrintWriter("C:/Users/Vicki/Desktop/CountryUnsortedFormat.txt");
String[] line = new String[238];
while (stdIn.hasNextLine()){
for (int k = 0; k <= line.length-1; k++){
line[k]=stdIn.nextLine();
out.println(line[k]);
out.close();
}
}
}
}
我的代码没有任何明显的问题,但我尝试打印出数组并得到一个“null”数组。我做错了吗?
编辑:将 PrintWriter 文件名更改为 CountryUnsortedFormat
【问题讨论】:
-
你不能用正确的答案来改变你的问题,这会导致以后来看这个问题的人产生误解。
-
您也有我提到的多个问题并在我的回答中更正它们。
标签: java arrays file printwriter sorted