Datasets:
ArXiv:
License:
Stack-Repo / data /train /akash-coded /FSD_Java /Lesson-3 /Exception Handling /Examples /TryWithResourcesExample.java
Download data/train/akash-coded/FSD_Java/Lesson-3/Exception Handling/Examples/TryWithResourcesExample.java from RepoFusion/Stack-Repo: direct link, hf CLI and curl.
- Browser
- Download file 593 Bytes
-
https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-3/Exception%20Handling/Examples/TryWithResourcesExample.java
- Command line
-
hf download 'hf://datasets/RepoFusion/Stack-Repo@bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-3/Exception Handling/Examples/TryWithResourcesExample.java'
-
curl -L -o TryWithResourcesExample.java https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-3/Exception%20Handling/Examples/TryWithResourcesExample.java
593 Bytes
| import java.io.FileOutputStream; | |
| public class TryWithResourcesExample { | |
| public static void main(String[] args) { | |
| // Using try-with-resources | |
| try (FileOutputStream fileOutputStream = new FileOutputStream("abc.txt")) { | |
| String msg = "Welcome to javaTpoint!"; | |
| byte[] byteArray = msg.getBytes(); // converting string into byte array | |
| fileOutputStream.write(byteArray); | |
| System.out.println("Message written to file successfuly!"); | |
| } catch (Exception exception) { | |
| System.out.println(exception); | |
| } | |
| } | |
| } | |