iteye_18009 2011-08-23 21:33
浏览 1145
已采纳

Linux下读取文件失败

这是我的读取代码:
[code="java"]
public static List addFileToList(String bKFilePath) {
BufferedReader bkFile = null;
List list = new ArrayList();
try {
LOG.debug("bKFilePath:"+bKFilePath);
boolean isReadable=new File(bKFilePath).canRead();
LOG.debug("is file readable:"+isReadable);
bkFile = new BufferedReader(new FileReader(bKFilePath));
String anotherRs = null;
while ((anotherRs = bkFile.readLine()) != null) {
LOG.info("fileContent:"+anotherRs+"\n");
list.add(anotherRs);
}
LOG.debug("addFileToList complete");
} catch (FileNotFoundException e) {
LOG.warn("没有找到文件:", e);
return null;
} catch (IOException e) {
LOG.warn("文件读取异常:", e);
return null;
} catch (RuntimeException e) {
LOG.warn("没有文件读写权限:", e);
return null;
} finally{
if(bkFile!=null){
try {
bkFile.close();
} catch (IOException e) {
LOG.warn("文件关闭异常:", e);
}
}
}
return list;
}
[/code]
在Linux系统上碰到的问题是:
1、首尾两端日志打印成功:"bKFilePath:","addFileToList complete";
2、中间的日志:"fileContent:",一行也没有打印。
这个方法理论上是没有错误的,我把文件复制到本地windows环境下测试是能够读取成功的。中间的日志也全部打印。
考虑过路径和权限问题,但日志中根本就没有的对应的异常信息。而且经过手工验证,路径是正确的,权限也没有问题,所在文件夹和文件本身分别是:drwxrwxrwx、rwxrwxrwx。
但这个文件就是死活读不出来。

  • 写回答

4条回答 默认 最新

  • laopeng301 2011-08-23 23:01
    关注

    [code="java"]liux下传入的路径格式是什么的?
    贴下你传的路径吧··
    然后
    window liunx下路径分隔符不同啊
    File.separator设定路径分隔符····
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog