Write entire file: Difference between revisions
→Using Java NIO
Line 628:
<syntaxhighlight>
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public final class WriteEntireFile {
public static void main(String[] aArgs) throws IOException {
String contents = "Hello World";
String filePath = "output.txt";
Files.write(Paths.get(filePath), contents.getBytes(), StandardOpenOption.CREATE);
}
}
</syntaxhighlight>
|