我有一个程序保存在一个文件上。当前的代码被设置为保存在特定路径上的文件,但是当我从另一台计算机上运行该程序时,该程序不起作用,我需要每次更改路径。对csv文件使用动态路径
public CreateCustomer() {
initComponents();
ArrayList<String> ConsIDList = new ArrayList<String>();
String csvFileToRead = "E:\\ryan_assignment_sit2\\ConsID\\consID.csv"; // Reads the CSV File.
BufferedReader br = null; // Creates a buffer reader.
String line = "";
String splitBy = ","; // Reader Delimiter
try {
br = new BufferedReader(new FileReader(csvFileToRead)); // Buffer Reader with file name to read.
Scanner reader = new Scanner(System.in);
while ((line = br.readLine()) != null) { //While there is a line to read.
reader = new Scanner(line);
reader.useDelimiter(splitBy);
while (reader.hasNext()) { // While there is a next value (token).
ConsIDList.add(reader.next());
}
}
} catch (FileNotFoundException exception) { // Exception Handler if the File is not Found.
exception.printStackTrace();
} catch (IOException exception) { // Input/Output exception
exception.printStackTrace();
} finally {
if (br != null) {
try {
br.close(); // Close the Scanner.
} catch (IOException exception) {
exception.printStackTrace();
}
}
我把文件中的子文件夹中的程序的名称ConsID,我尝试的路径文件更改为
String csvFileToRead = "..\\ConsID\\consID.csv";
但文件不能从程序读取。
程序将运行只在基于Windows的计算机上,所以我不认为这会影响。但我需要在多台计算机上打开该程序,我想知道是否可以设置从该程序的根文件夹读取的路径 –
将其放入共享文件夹并使用HTTP访问它,以便可以读取文件。 – Shriram
每台计算机都需要有一个单独的文件,因此理想情况下该文件将位于应用程序的同一文件夹中。我正在寻找的是一种使用动态路径的方式,就像程序将直接搜索从 –