【问题标题】:PrintWriter not allowing me to enter a specific directoryPrintWriter 不允许我输入特定目录
【发布时间】:2016-07-28 05:50:26
【问题描述】:
try{
    pw = new PrintWriter("C:\\Users\\SDSAD\\Desktop\\java\\file.txt");
}catch(Exception exc){
    System.out.println();
}

最近一直在玩 IO,我正在尝试使用 PrintWriter,它一开始就可以工作,例如当我刚刚输入时:

pw = new PrintWriter("file.txt");

它工作得很好,是我不允许在 PrintWriter 中设置特定目录还是我做错了什么?

【问题讨论】:

    标签: java io printwriter


    【解决方案1】:

    PrintWriter 只能用于文件,请参阅 javadocs:

    * @param  fileName
    *         The name of the file to use as the destination of this writer.
    *         If the file exists then it will be truncated to zero size;
    *         otherwise, a new file will be created.  The output will be
    *         written to the file and is buffered.
    

    在目录上运行时你希望它做什么?

    编辑:问题改变后。

    您做得很好,我希望您在给定目录中没有该文件,或者您没有读取权限来访问它。

    【讨论】:

    • 我的错字,最初我有file.txt。我的错。
    猜你喜欢
    • 2023-03-12
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多