I am trying to access a file like this:
public class Main {
private static class RemoteAdapter implements SpellcheckerRemoteAdapter {
private Spellchecker spellchecker;
private String fileName = "deutsch.txt";
File file = new File(getClass().getClassLoader().getResource(fileName).getFile());
private RemoteAdapter() {
this.spellchecker = SpellcheckerFactory.createSpellchecker(file);
}
@Override
public boolean check(String word) {
return this.spellchecker.check(word);
}
@Override
public List < String > getProposal(String word) {
return this.spellchecker.getProposal(word);
}
}
public static void main(String[] args) {
System.out.println("Start Server");
try {
Registry registry = LocateRegistry.createRegistry(1088);
SpellcheckerRemoteAdapter adapter = new RemoteAdapter();
UnicastRemoteObject.exportObject(adapter, 0);
registry.rebind(SpellcheckerRemoteAdapter.NAME, adapter);
} catch (RemoteException re) {
System.out.println(re.getMessage());
}
System.out.println("Server is running!");
}
}
When I run my code inside of eclipse it works just fine. But if I export the project as a runnable jar I get the following error:
java.io.FileNotFoundException: file:\C:\Users\Linsane\Desktop\server\SpellcheckerServer.jar!\deutsch.txt (The filename, directory name, or volume label syntax is incorrect)
Although I know that the file is in this location and as I don't build the path myself I don't really get what went wrong.