Eclipse プロジェクトがあり、1 つのフォルダーにテキスト ファイル "conf.txt" があります。コンピューターでパスを使用すると、ファイルを読み書きできます。しかし、ワークスペース フォルダーだけでなく、そこにも独自のフォルダーを作成する必要があります。他の人のためにプログラムをコミットしたいのですが、プログラムが別のコンピューターで実行されているため、プログラムに入力したパスが機能しません。私が必要とするのは、ワークスペース内のパスのみでファイルを使用できるようにすることです。
ワークスペースにあるパスを入力しただけでは機能しません。
これは、私のクラス ファイルがどのように見えるかです。
public class FileUtil {
public String readTextFile(String fileName) {
String returnValue = "";
FileReader file = null;
try {
file = new FileReader(fileName);
BufferedReader reader = new BufferedReader(file);
String line = "";
while ((line = reader.readLine()) != null) {
returnValue += line + "\n";
}
reader.close();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (file != null) {
try {
file.close();
} catch (IOException e) {
// Ignore issues during closing
}
}
}
return returnValue;
}
public void writeTextFile(String fileName, String s) throws IOException {
BufferedWriter output = new BufferedWriter(new FileWriter(fileName));
try {
output.write(s);
}
finally {
output.close();
}
}
}
誰かが何をすべきか知っていることを願っています。
ありがとう!