Java. Io. ioexception: no such file or directory

Source: Internet
Author: User

 Exception Information

java.io.IOException: No such file or directoryat java.io.FileOutputStream.writeBytes(Native Method)at java.io.FileOutputStream.write(FileOutputStream.java:247)at com.nstc.framework.web.util.jsloader.JsFileModelMgrTest.testGetJs(JsFileModelMgrTest.java:53)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:585)at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)

 

Cause of exception

There are too many such exceptions. This is only one of the reasons. When a file stream instance is created and filechannel is used, the file content is operated through NiO, disable filechannel after the operation is complete. If you try to write it here, an error will be thrown.

Code

    @Test    public void testGetJs() {        jfmmInst.doLoaderJs();        FileOutputStream fous = null;        FileChannel fileChannel = null;        try {            fous = new FileOutputStream(testFile, false);            fileChannel = fous.getChannel();            jfmmInst.doRestoreIO("ExtExtension", fileChannel);            fileChannel.close();            fous.write("HelloWorld\n".getBytes());        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException ioe) {            ioe.printStackTrace();        } finally {            if (fous != null) {                try {                    fous.close();                } catch (IOException ioe) {                    ioe.printStackTrace();                }            }        }    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.