我做了一個簡單的應用程序,要求用戶輸入一個文件夾名稱,以便稍後複製一些文件。問題是該文件夾名稱將包含非lating(希臘)字符。雖然該文件夾正在創建正確的名稱和沒有錯誤,當我將它的AbsolutePath存儲在一個字符串希臘字符得到這樣的?????? _22-03-2012。所以當我嘗試使用存儲路徑發送複製的文件時,我得到錯誤,因爲java無法正確讀取路徑!Java文件路徑編碼?
任何想法? (顯然,我是新與Java所以裸跟我PLZ!)
package newOrderAndXCopy;
import java.io.File;
import javax.swing.JOptionPane;
import initiate.*;
public class NewOrder {
private String orderPath = null;
//constructor
public NewOrder() {
if(newOrderName()) {
File nO = new File(orderPath);
nO.mkdir();
}
}
public boolean newOrderName() {
boolean name = false;
int counter = 3;
while(counter > 0) {
String test = JOptionPane.showInputDialog("Here I ask the user to give the order name with this form -> ΠΑΡΑΛΑΒΗ ΧΧ-ΧΧ-ΧΧΧΧ (π.χ. ΠΑΡΑΛΑΒΗ 12-04-2013):");
if(!test.matches("ΠΑΡΑΛΑΒΗ \\d{2}-\\d{2}-\\d{4}")) {
JOptionPane.showMessageDialog(null, "Wrong name!", "Error", JOptionPane.ERROR_MESSAGE);
counter--;
}
else {
//replace the space with underscore
String rep = Config.savesPath + test.replaceAll(" ", "_") + "/";
File no = new File(rep);
if(!no.exists()) {
orderPath = rep;
--> Config.orderPath = no.getAbsolutePath(); <--
/*This part is where it gets messy. The folder is created but this value is wrong so I can't use it later!*/
name = true;
JOptionPane.showMessageDialog(null, "The order folder was created!!", "Success!", JOptionPane.INFORMATION_MESSAGE);
break;
}
else {
JOptionPane.showMessageDialog(null, "The order with this name already exists!Pick another Name!", "Error", JOptionPane.ERROR_MESSAGE);
}
}
}
return name;
}
}
這可能是一個顯示問題,而不是數據存儲在File對象中的問題。你能否展示一些代碼來演示你如何生成文件以及如何打印路徑? – 2013-04-25 13:44:36