有誰知道Java如何能夠規避Windows MAX_PATH限制。使用下面的代碼,我能夠在Java中創建一個非常長的路徑,並且能夠執行I/O,而使用不帶前綴\\?\的窗口是不可能的。Java如何規避Windows MAX_PATH WinAPI限制
public static void main(String[] args) throws IOException {
BufferedWriter bufWriter = null;
try {
StringBuilder s = new StringBuilder();
for (int i = 0; i < 130; i++) {
s.append("asdf\\");
}
String filePath = "C:\\" + s.toString();;
System.out.println("File Path = " + filePath);
File f = new File(filePath);
f.mkdirs();
f = new File(f, "dummy.txt");
System.out.println("Full path = " + f);
bufWriter = new BufferedWriter(new FileWriter(f));
bufWriter.write("Hello");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (bufWriter != null) {
bufWriter.close();
}
}
}
您使用的是哪個版本的Windows? – 2012-04-10 18:32:38
我正在使用Windows 7 ... – Rajiv 2012-04-10 18:38:02