I've a textfile called backUp.dat. That file contains a directory path, so I created a simple method to read that file:
public static String readFileAsString(String filename) {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(filename));
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
reader.close();
//System.out.println("Current Directory:"+ new File(".").getAbsolutePath());
return sb.toString();
} catch (FileNotFoundException ex) {
Logger.getLogger(Welcome.class.getName()).log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(null, "Il Manque un Fichier de System Contactez Votre Fournisseur","ERREUR",JOptionPane.ERROR_MESSAGE);
System.exit(0);
} catch (IOException ex) {
Logger.getLogger(Welcome.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
This work perfectly, but here is the problem:
String dir = readFileAsString("backUp.dat");
File fileEES = new File(dir+"backUp.XML");
if (fileEES.createNewFile()) {
System.out.println("File is created!");
} else {
System.out.println("File already exists.");
}
I get this exception:
sept. 08, 2015 10:22:28 PM credittaxiphone.FirstWindow exporterUserInfo
GRAVE: null
java.io.IOException: La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:1012)
at credittaxiphone.FirstWindow.exporterUserInfo(FirstWindow.java:565)
at credittaxiphone.FirstWindow.exit(FirstWindow.java:116)
at credittaxiphone.FirstWindow.formWindowClosing(FirstWindow.java:413)
at credittaxiphone.FirstWindow.access$100(FirstWindow.java:42)
at credittaxiphone.FirstWindow$1.windowClosing(FirstWindow.java:179)
at java.awt.Window.processWindowEvent(Window.java:2058)
at javax.swing.JFrame.processWindowEvent(JFrame.java:305)
at java.awt.Window.processEvent(Window.java:2017)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
On the line:
File fileEES = new File(dir + "backUp.XML");
If I remove dir
it works correctly.
The content of backUp.dat is:
D:\\