首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AsynchronousFileChannel抛出java.nio.file.NoSuchFileException

AsynchronousFileChannel抛出java.nio.file.NoSuchFileException
EN

Stack Overflow用户
提问于 2015-03-01 04:58:31
回答 1查看 337关注 0票数 1

我正在玩java nio 2,我写了一个简单的应用程序,应该创建一个文件并将内容写入其中,但我得到了文件不存在异常。

代码语言:javascript
复制
ByteBuffer buffer = ByteBuffer.wrap("jhkjhkhjkhkjhkjhkjhkjhkhkjhkjhkjh".getBytes());

    Path path = Paths.get("F:", "dummyFile.txt");

    try(AsynchronousFileChannel asynchronousFileChannel =
            AsynchronousFileChannel.open(path, StandardOpenOption.CREATE_NEW)) {
        Future<Integer> future = asynchronousFileChannel.write(buffer, 0);
        while (!future.isDone()) {
            System.out.println("waiting");
        }

        System.out.println(String.format("Done - bytes written %d", future.get()));


    } catch (Exception e) {
        System.out.println(e.toString());
    }
EN

回答 1

Stack Overflow用户

发布于 2015-03-01 05:03:44

好了,我发现我应该添加写选项

代码语言:javascript
复制
AsynchronousFileChannel asynchronousFileChannel =
            AsynchronousFileChannel.open(path, StandardOpenOption.CREATE, StandardOpenOption.WRITE)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28786805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档