文件读写跨Linux平台遭遇权限问题?在线等
byml 2005-02-02 04:31:54 在windows 平台下开发的一个新闻发布系统,要向文件里读写信息,代码如下,在windows平台使用正常。
public class FileManager {
public FileManager() {
}
public static synchronized String read(String fileName) throws Exception {
String content = null;
try {
FileInputStream fileinputstream = new FileInputStream(fileName);
int size = fileinputstream.available();
byte b[] = new byte[size];
fileinputstream.read(b);
fileinputstream.close();
content = new String(b);
} catch (IOException ioexception) {
throw new Exception("文件读取失败");
}
return content;
}
public static void save(String path, String fileName, String content) throws
Exception {
if (!path.endsWith("\\")) {
path += "\\";
}
try {
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
FileOutputStream fileoutputstream = new FileOutputStream(path +
fileName);
byte b[] = content.getBytes();
fileoutputstream.write(b);
fileoutputstream.close();
} catch (IOException ioexception) {
throw ioexception;
}
}
public static void save(String fileName, String content) throws Exception {
int pos = fileName.lastIndexOf("\\");
String path = fileName.substring(0, pos);
String name = fileName.substring(pos + 1);
save(path, name, content);
}
}
但是当把系统发布到Linux平台后,文件读取失败,这是什么问题呢,Linux对文件读写有权限限制?把访问权限码改成777依旧不行,请高手给一个在两个平台上都能正常运行的解决方案。