I’m working on a database-related project and i have a MS-Access Database located at:
D:\My Documents\Database.accdb
So i use the following command for running MS-Access:
cmd /c start MSACCESS D:\My Documents\database.accdb
In java:
view.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent E) {
String[] command = {"cmd", "/c", "start MSACCESS D:\\My Documents\\Database.accdb"}
Runtime.getRuntime().exec(command);
}
});
Microsoft Access inmediatly starts but throws the following error:
“The command line you used to start Microsoft Office Access contains an option that Micosoft Access doesn’t recognize”
And then:
“The database file ‘D:\My.mdb’ cannot be found”
So i assumed that it doesn’t recognise the space at: “My Documents” and it truncates at “My”, so i try it’s NTFS 8.3 equivalent: D:\MYDOCU~1\Database.accdb, and throws:
“The database file ‘D:\MYDOCU~1\Database.accdb’ cannot be found”
I really don’t know whats wrong
“D:\My Documents\Database.accdb” contains a space and is being treated as an additional parameter (so it would like like
{"cmd", "/c", "start", "MSACCESS", "D:\\My", "Documents\\Database.accdb"}to the calling program)Use something like
instead…
UPDATE
Trying to “shorten” the path names manually is very dangerous and ill advised. If you need to go this route, you really should take advantage of a native call to the OS to tell how the name should be shortened, so both you and the OS know that you’re talking about the same thing
ADDITIONAL
Also, try running the command from the command prompt just to make sure it works 😉