/****************************************************************************** * This program simply writes characters from the alphabet to a file. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ import java.io.BufferedWriter; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.FileSystems; import java.nio.file.Files; import org.pureprogrammer.Utils; public class FileIO4 { static void writeTextFile(String filespec) throws IOException { BufferedWriter ofh = Files.newBufferedWriter(FileSystems.getDefault().getPath(filespec), Charset.forName("UTF-8")); // Latin alphabet for (int c = 0x41; c <= 0x5A; ++c) { ofh.write(c); } ofh.write("\n"); // Greek alphabet for (int c = 0x391; c <= 0x3A9; ++c) { ofh.write(c); } ofh.write("\n"); // Cyrillic alphabet for (int c = 0x410; c <= 0x42F; ++c) { ofh.write(c); } ofh.write("\n"); // Katakana alphabet for (int c = 0x30A0; c <= 0x30FF; ++c) { ofh.write(c); } ofh.write("\n"); ofh.flush(); try {ofh.close();} catch (IOException ex) {}; } public static void main(String[] args) { if (args.length != 1) { System.out.println(Utils.join("", "Syntax: ", "FileIO4", " {filename}")); System.exit(1); } final String FILESPEC = args[0]; try { writeTextFile(FILESPEC); } catch (IOException ex) { System.out.println(Utils.join("", "Error: ", Utils.exceptionMessage(ex))); } catch (Exception ex) { System.out.println("Unexpected File Read Error"); } } }