1

Hello I am creating a chat bot web application using program ab in java. If I access the files from external storage, it is working. If I store the files inside my project, it is not working? I don't know what is the problem.

This code is not working, ServerCode is my project name in eclipse.

String botName = "super";
String botPath = "ServerCode/aiml";
Bot bot = new Bot(botName, botPath);
Chat chatSession = new Chat(bot);
String request =  msg.toUpperCase();
String response = chatSession.multisentenceRespond(request);    
System.out.println(response);

While this code is working,

String botName = "super";
String botPath = "E:\ab";
Bot bot = new Bot(botName, botPath);
Chat chatSession = new Chat(bot);
String request =  msg.toUpperCase();
String response = chatSession.multisentenceRespond(request);    
System.out.println(response);

What is the problem? how to store the folders and its sub folders inside the project, so that when I can create war file, I include those files in that war file.

Kavipriya
  • 441
  • 4
  • 17

1 Answers1

0

There is no problem with where you are storing the files, the problem is how you accessed it. The files get stored in some other location when u export it to war file, so you can't access the files. So by changing the way you access the files as below, it will work fine.

String botPath = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
String botName = "super";
String botPath = "E:\ab";
Bot bot = new Bot(botName, botPath);
Chat chatSession = new Chat(bot);
String request =  msg.toUpperCase();
String response = chatSession.multisentenceRespond(request);    
System.out.println(response);
Kavipriya
  • 441
  • 4
  • 17