我创建了一个简单的程序,它使用不同的算法对输入文件中的整数进行排序。我还使用文件写入器将结果输出到另一个文件。不幸的是,无论我如何更改代码,文件都会被覆盖。有什么建议吗?
一直在谷歌上寻找答案,并尝试改变我输入语法的方式,但没有任何效果。
重要的位:
设置作家
try {
FileWriter fileWriter = new FileWriter ("Sorted output.txt");
//BufferedWriter bufferedWriter = new BufferedWriter (fileWriter);
PrintWriter out = new PrintWriter (new FileWriter("Sorted output.txt", true));
输出到文件
out.println("User's own data set sorted using bubble sort.");
out.println(unsortedArray + Arrays.deepToString(FileOne));
out.println("Sorted Array looks like this:" + Arrays.toString(intArrayBubble));
out.println(timeToSort + bubbleSortIs + bubbleTime + "ms");
它工作正常,但是它在 do while 循环中使用,带有嵌套的 if 语句,并且每个语句都覆盖另一个。
其余代码以防万一需要 - 更新 - 仍然无法正常工作
import java.io.*;
import java.util.*;
import java.util.concurrent.TimeUnit;
public class PDD_Sorting {
public static void main (String [] pArgs)
{
//Array for a file
String[] FileOne;
FileOne = new String[0];
int optionOne = 1,
optionTwo = 2,
optionThree = 3,
secondaryOptionOne = 1,
secondaryOptionTwo = 2,
secondaryOptionThree = 3,
userSelection,
subUserSelection;
String unsortedArray = "Unsorted array is: ",
bubbleSort = "Sorted array using bubble sort: ",
selectionSort = "Sorted array using selection sort: ",
insertionSort = "Sorted array using insertion sort: ",
timeToSort = "Time needed to sort this array using ",
bubbleSortIs = "bubble sort is ",
selectionSortIs = "selection sort is ",
insertionSortIs = "insertion sort is ",
文件不断被覆盖,我该如何阻止它并将其添加到文件中?
拉莫斯之舞
江户川乱折腾
相关分类