首页 > 解决方案 > Trying to re-direct path of a file from c drive to tomcat apache server

问题描述

Is there a way to change the path of a file present in C folder in a java program and put it into tomcat apache server. This whole code is running on Eclipse IDE and a java program takes the path of a file which is present in C: of the local machine. Can I change that path and somehow store or re-direct that path from the Tomcat apache server.

We are running the code through tomcat apache server on the local machine, now we would like to implement CI/CD pipeline and host the code on rancher for which the code is hosted on gitlab first and then the pipeline starts. Is there a way I can change this path and store the file in tomcat apache server or re-direct the path of the file from the server. Or will the project face any problem when processing through the pipeline? I'm using eclipse as IDE. Any help is much appreciated.

private final static String Word2VecModelPath = "C:\\german.model";
 // change this path 

标签: javaeclipseapachetomcat

解决方案


这里:

private final static String Word2VecModelPath = "C:\\german.model"

那不是文件系统上的“路径”!此时,它只是一个字符串,一个字符序列。您可以转向操作系统,鉴于此字符串类似于本地文件系统中的目录,您可以使用 Java API 访问相应的文件。

问题是:该文件是位于本地计算机上还是位于远程系统上并不重要。对于您的用例而言,重要的是您可以通过文件系统访问它。

换句话说:如果您的服务器将其文件写入网络驱动器,并且您的客户端可以访问该驱动器,那么您只需更改该路径字符串,以指向不同的驱动器。

但最有可能的是,事情更复杂:因为该资源不在您有权访问的某个文件系统上。

然后,您必须首先与您的服务器通信,然后从那里下载该文件。

换句话说,你首先要了解访问本地文件系统中的文件与某些服务器拥有的资源之间的区别,并且只能通过该服务器提供的 API访问.


推荐阅读