哪里包含aiml bot文件

时间:2017-03-27 12:52:51

标签: java war aiml

您好我正在使用program ab中的java创建聊天机器人Web应用程序。如果我从外部存储访问文件,它正在工作。如果我将文件存储在我的项目中,它不起作用?我不知道是什么问题。

此代码无效,ServerCode是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);

虽然此代码正常运行,

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);

有什么问题?如何在项目中存储文件夹及其子文件夹,这样当我可以创建war文件时,我将这些文件包含在war文件中。

1 个答案:

答案 0 :(得分:0)

存储文件的位置没有问题,问题在于您如何访问它们。当您将文件导出到war文件时,文件会存储在其他位置,因此您无法访问这些文件。因此,通过更改您访问文件的方式,它将正常工作。

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);