If the file does not exist, what will readalllines return?

The Oracle document says here, files The readalllines (path, charset CS) method returns the lines in the file as list < string >

Solution

It doesn't "return" anything As Javadoc said, the readalllines method will throw IOException in case of I / O error

Specifically, when the file does not exist, the implementation of JDK 8 I am using will throw Java nio. file. Nosuchfileexception, which is a subclass of IOException

This is really not your concern This is why there are interfaces and encapsulation, so you don't need to look inside The important thing is that it is an object that respects the list interface contract

If you have to know, you can call on the returned object Getclass() to check The implementation of JDK 8 I'm using just returns Java util. ArrayList. Another implementation may return other content. As I mentioned earlier, we shouldn't even try to see what it is to avoid any risk of breaking the encapsulation

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>