【问题标题】:Where to include aiml bot files在哪里包含目标机器人文件
【发布时间】:2017-03-27 12:52:50
【问题描述】:

您好,我正在使用 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 文件中。

【问题讨论】:

    标签: java war aiml


    【解决方案1】:

    存储文件的位置没有问题,问题在于您如何访问它。当您将文件导出到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);
    

    【讨论】:

      猜你喜欢
      • 2014-01-06
      • 2011-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-30
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多