0
我對Java比較陌生,似乎無法弄清楚什麼是錯誤的,我研究了這個問題,即使我遵循了它的教程,我仍然無法做到它工作中,它看到的文件,因爲它給出了不同的錯誤,當我嘗試打開,實際上不存在的文件,但它不能從數據庫中獲取的變量Java JSON無法獲取數據庫值
我的代碼:
String userEnteredString = UserEntered.getText();
String userHomeLocal = Tutschedule.userHome;
FileReader dataFile = null;
try {
dataFile = new FileReader(userHomeLocal+"/Users/"+userEnteredString+".data");
} catch (FileNotFoundException ex) {
Logger.getLogger(LoginForm.class.getName()).log(Level.SEVERE, null, ex);
}
String dbData = dataFile.toString();
System.out.println(dbData);
JSONObject dataInfo = (JSONObject)dbData.parse(dataFile);
這裏是我的進口:
import java.io.*;
import java.util.Iterator;
//import java.io.FileNotFoundException;
import org.json.*;
//import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.parser.*;
這裏是寫入數據庫的部分,我相信問題並不在於此,因爲它寫得很好,因爲我檢查了它創建的數據庫以及它在那裏(發送用戶登錄表單的行不在那裏當我現在要爲用戶創建):
public class Tutschedule {
// TODO Add the MySQL Database Support
public static String userHome;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws JSONException {
boolean loggedIn = false;
if (loggedIn != true) {
LoginForm.LoginForm();
}
userHome = System.getProperty("user.home")+"/TutSchedule";
System.out.print(userHome);
Scanner scan = new Scanner(System.in);
String username = scan.next();
String password = scan.next();
JSONObject user = new JSONObject();
user.put("username", username);
user.put("password", password);
boolean dirCreate;
String directories =userHome+"/Users";
dirCreate = (new File(directories)).mkdirs();
try {
FileWriter userDataFile = new FileWriter(userHome+"/Users/"+username+".data");
userDataFile.write(user.toString());
userDataFile.flush();
userDataFile.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(user);
}
}
你可以發佈錯誤堆棧嗎? – PearsonArtPhoto