Burning to disk without using java.io

Suppose the use of java.io blocked. What are some alternative ways of writing, say, a simple text file called "Hello World!" to disk using Java / Groovy language features?

+6
source share
2 answers

If only java.io blocked (you said that java.io import is blocked), you can use java.nio to write to files.

Look at the Files center. In java.nio files / folders are represented by java.nio.Path objects, which are also part of the java.nio package (and not java.io ).

Example record "Hello World!" to text file to disk:

 Files.write(Paths.get("/your/folder/text.txt"), "Hello World!".getBytes(StandardCharsets.UTF_8)); // Or Files.write(Paths.get("/your/folder/text.txt"), Arrays.asList("Hello World!"), StandardCharsets.UTF_8); 
+4
source

JNI talk directly with the base OS API.

+3
source

Source: https://habr.com/ru/post/975024/


All Articles