我有一些打印到控制台的void函数。但是,我必须将它们写入文本文件,这就是为什么,我使用
PrintStream out = new PrintStream(newFileOutputStream("Programoutput.txt"));
System.setOut(out);
在我的主要功能的开头。但是运行程序后的输出文件包含一些中文字符。知道为什么会这样吗?你可以在下面找到我的代码。我正在使用Ubuntu 16.04(可能会影响)。
public static void main(String[] args) throws Exception {
path = args[0];
PrintStream out = new PrintStream(new FileOutputStream("Programoutput.txt"));
System.setOut(out);
long startTime = System.nanoTime();
// Set up Commands to Array
String[] commands = new String[numOfLines(path)];
setUpArray(path, commands);
// Build Memory
int memorySize = Integer.parseInt(commands[0].split(" ")[1]);
String replacement = commands[1].split(" ")[1];
String searchStructure = commands[2].split(" ")[1];
// Creating Data Structure Objects
Queue memory = new Queue(memorySize);
BST binaryTree = new BST();
ModifiedQueue mq = new ModifiedQueue(memorySize);
MaxHeapTree hTree = new MaxHeapTree(memorySize);
if(replacement.equals("FIFO") && searchStructure.equals("BinarySearch")){
fifoQueue(memory, binaryTree, commands);
}else if(replacement.equals("PriorityQueue") && searchStructure.equals("BinarySearch")){
priorityQueue(hTree, binaryTree, commands);
}else if(replacement.equals("SecondChance") && searchStructure.equals("BinarySearch")){
secondChanceQueue(mq, binaryTree, commands);
}
long endTime = System.nanoTime() - startTime;
double totalTime = endTime/1e9;
System.out.println("Elapsed time in seconds: " + totalTime);
}