首先,我使用的是Ubuntu! :)在Java应用程序中使用“pathdir”
我需要一些帮助这里, 我建了一个Java应用程序,我想设置默认路径树,就像这样:
> cd /anyDirectory/meuRestaurante
> ls
bin/ data/
> cd bin
> ls
meuRestaurante.jar
> cd ..
> cd data
> ls
Cartoes.txt Clientes.txt
我想,我的Java应用程序保存这些TXT的文件上/data
目录,同时是/bin
目录。 Exctaly,应该怎么如果我使用这些功能来读取/保存TXT的文件:
public static String readFile(String fileName) {
try {
File file = new File("."+fileName);
FileReader reader = new FileReader(file);
BufferedReader in = new BufferedReader(reader);
String string;
String returnString = "";
while ((string = in.readLine()) != null) {
returnString = "" + returnString + string;
}
in.close();
return returnString;
} catch (IOException e) {
System.err.println("readFile " + e.getMessage());
return null;
}
}
public static boolean writeFile(String fileName, String newContent){
try {
BufferedWriter out = new BufferedWriter(new FileWriter(fileName, true));
out.write(newContent);
out.close();
return true;
}catch(IOException e){
System.err.println("writeFile " + e.getMessage());
return false;
}
}
如何应该是fileName
?
任何人有小费?