![]() ![]() The sharp eyed amongst you will also realise we haven’t dealt with the MalformedURLException either. The above code can be reduced down to: URL url = new URL(" ") Now as Alan Bateman (lead for the NIO.2 project) has kindly pointed out, the latest developer preview of JDK 7 (build130) makes the actual file I/O work much simpler. Try (FileOutputStream fos = new FileOutputStream(new File("output.txt")) Notice that the TWR feature automatically handles closing of the FileOutputStream and InputStream resources. In the following example, the HTML content from an URL is read and written in a file. They reflect some of the changes from the new Java specification. You can go ahead and copy/paste the following code snippets directly in your IDE.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |