ディレクトリを作成しようとしていますが、毎回失敗するようですか?私はそれも許可の問題ではないことを確認した、私はそのディレクトリに書き込む完全な許可を持っています。前もって感謝します。ここでJava - mkdir()ディレクトリを作成しない
はコードです:ここでは
private void writeTextFile(String v){
try{
String yearString = convertInteger(yearInt);
String monthString = convertInteger(month);
String fileName = refernce.getText();
File fileDir = new File("C:\\Program Files\\Sure Important\\Report Cards\\" + yearString + "\\" + monthString);
File filePath = new File(fileDir + "\\"+ fileName + ".txt");
writeDir(fileDir);
// Create file
FileWriter fstream = new FileWriter(filePath);
try (BufferedWriter out = new BufferedWriter(fstream)) {
out.write(v);
}
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
private void writeDir(File f){
try{
if(f.mkdir()) {
System.out.println("Directory Created");
} else {
System.out.println("Directory is not created");
}
} catch(Exception e){
e.printStackTrace();
}
}
public static String convertInteger(int i) {
return Integer.toString(i);
}
Calendar cal = new GregorianCalendar();
public int month = cal.get(Calendar.MONTH);
public int yearInt = cal.get(Calendar.YEAR);
が出力されます。
Directory is not created
Error: C:\Program Files\Sure Important\Report Cards\2012\7\4532.txt (The system cannot find the path specified)
問題であるように思わ乾杯それが:)に私をalowsとき、私は答えを受け入れます感謝!!! – Nick
パス名の "動的な"部分には2つのディレクトリがあるので、この理論はかなり良いと言えるでしょう... –
あなたのコードをコピーしてmkdirs()に変更しました。関連コードを含むように編集する –