String filePath = "E:/"; String fileName = "X1logRecords.txt"; String linuxFilePath = "/usr/" + fileName; static boolean isOpen = true; //switch private File file;
// static boolean isLinux = true; //ok 甚至可以把这边开关放到其他类中,免得搅不清。
private static X1RecordsToFile records = new X1RecordsToFile(); //依赖于isLinux
static boolean isLinux = true; //error private X1RecordsToFile(){ //isLinux = true; String pathname = filePath + fileName; if (true == isLinux){ //linux file = new File(linuxFilePath); if (file.exists()) { file.delete(); } try { file.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); } }
else{ //windows file = new File(pathname); if (file.exists()) { file.delete(); } try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } }
一直是windnws的目录,不是linux的,因为isLinux一直是false。