1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
package Torello.Java;

import java.io.*;
import java.util.*;
import java.util.zip.*;
import java.util.stream.*;
import java.nio.file.*;
import java.lang.reflect.InvocationTargetException;

import Torello.Java.Additional.*;

import Torello.HTML.Tools.JavaDoc.StaticFunctional;
import Torello.HTML.Tools.JavaDoc.Excuse;

/**
 * <CODE>File Read / Write - Documentation.</CODE><BR /><BR />
 * <EMBED CLASS="external-html" DATA-FILE-ID="FRW">
 */
@StaticFunctional(Excused="TRUNCATE_EOF_CHARS", Excuses=Excuse.FLAG)
public class FileRW
{
    private FileRW() { }

    /**
     * This is used by method {@link #loadFileToString(String)}.  By default this flag is set to
     * <B>TRUE</B>, and when it is, any trailing {@code EOF chars, ASCII-0} found in a file that
     * is to be interpreted as a text-file, will be truncated from the {@code String} returned by
     * that {@code 'reader'} method.
     */
    public static boolean TRUNCATE_EOF_CHARS = true;

    // ********************************************************************************************
    // writeFile
    // ********************************************************************************************


    /**
     * Writes the entire contents of a single {@code java.lang.String} to a file on the file-system
     * named {@code 'fName'}.
     *
     * <BR /><BR /><B>NOTE:</B> Though the file does not need to exist already in order for this
     * file to be written (in fact, if it does exist - <I>it will be 'over-written'</I>) the
     * directory hierarchy needs to exist, or a java {@code 'IOException'} will occur.
     *
     * @param s A {@code java.lang.String} which is appended, in entirety, to the file ('fName')
     *
     * @param fName The name of the file to which the contents of the {@code java.lang.String}
     * are appended.  If This file doesn't already exist, it is created here.
     *
     * @throws IOException If any I/O errors have occurred with the file-system / disk.
     */
    public static void writeFile(CharSequence s, String fName) throws IOException
    {
        File outF = new File(fName);
        outF.createNewFile();
        FileWriter fw = new FileWriter(outF);
        fw.write(s.toString());
        fw.close();
    }

    /** Convenience Method.  Invokes {@link #writeFile(Iterator, String)} */
    public static void writeFile(Iterable<String> i, String fName) throws IOException
    { writeFile(i.iterator(), fName); }

    /** Convenience Method.  Invokes {@link #writeFile(Iterator, String)} */
    public static void writeFile(Stream<String> stringStream, String fName) throws IOException
    { writeFile(stringStream.iterator(), fName); }

    /**
     * This takes an {@code Iterator<String>}, and a filename, and writes each
     * {@code java.lang.String} in the {@code Iterator} to the file named by parameter
     * {@code 'fName'}
     *
     * <BR /><BR /><B><I>NOTE:</I></B> A newline {@code ('\n')} is appended to the end of each
     * {@code java.lang.String} before writing it to the file.
     *
     * <BR /><BR /><B>ALSO:</B> Though the file does not need to exist already in order for this
     * file to be written (in fact, if it does exist - <I>it will be 'over-written'</I>) the
     * directory hierarchy needs to exist, or a java {@code 'IOException'} will occur.
     *
     * @param i This is any java {@code Iterable<String>} object.  Each of these will be written,
     * in succession, to the file named by parameter {@code 'fName'}
     *
     * @param fName The name of the file to which the contents of the {@code java.lang.String}
     * are appended.  If This file doesn't already exist, it is created here.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or
     * disk operation.
     */
    public static void writeFile(Iterator<String> i, String fName) throws IOException
    {
        File outF = new File(fName);
        outF.createNewFile();
        FileWriter fw = new FileWriter(outF);
        while (i.hasNext()) fw.write(i.next() + "\n");
        fw.close();
    }


    // ********************************************************************************************
    // writeFile_NO_NEWLINE
    // ********************************************************************************************


    /** Convenience Method.  Invokes {@link #writeFile_NO_NEWLINE(Iterator, String)} */
    public static void writeFile_NO_NEWLINE(Iterable<String> i, String fName)
        throws IOException
    { writeFile_NO_NEWLINE(i.iterator(), fName); }

    /** Convenience Method.  Invokes {@link #writeFile_NO_NEWLINE(Iterator, String)} */
    public static void writeFile_NO_NEWLINE(Stream<String> stringStream, String fName)
        throws IOException
    { writeFile_NO_NEWLINE(stringStream.iterator(), fName); }

    /**
     * This takes an {@code Iterator} of String, and a filename and writes each
     * {@code java.lang.String} in the {@code Iterator} to the file named by parameter
     * {@code 'fName'}
     *
     * <BR /><BR /><B>NOTE:</B> in this function a newline {@code ('\n')} character <I>is 
     * <B>not</B> appended</I> to the end of each {@code java.lang.String} of the input
     * {@code Iterator}.
     *
     * <BR /><BR /><B>ALSO:</B> Though the file does not need to exist already in order for this
     * file to be written (in fact, if it does exist - <I>it will be 'over-written'</I>) the
     * directory hierarchy needs to exist, or a java {@code 'IOException'} will occur.
     *
     * @param i This is any java {@code 'Iterable'} object that can iterate {@code 'String'}.
     * Each of these will be written, in succession, to the file named by {@code 'fName'}
     *
     * @param fName The name of the file to which the contents of the {@code java.lang.String}
     * are appended.  If This file doesn't already exist, it is created here.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     */
    public static void writeFile_NO_NEWLINE(Iterator<String> i, String fName) throws IOException
    {
        File outF = new File(fName);
        outF.createNewFile();
        FileWriter fw = new FileWriter(outF);
        while (i.hasNext()) fw.write(i.next());
        fw.close();
    }


    // ********************************************************************************************
    // appendToFile
    // ********************************************************************************************


    /**
     * Appends the entire input {@code java.lang.String} - actually a
     * {@code java.lang.CharSequence} to the file on the file-system named {@code 'fName'}
     *
     * <BR /><BR /><B>NOTE:</B> Though the file does not need to exist already in order for this
     * file to be written the directory hierarchy needs to exist, or a java {@code 'IOException'}
     * will occur.
     *
     * @param s A {@code java.lang.CharSequence} (almost identical to {@code 'String'}) which is
     * appended, in entirety, to the file-name parameter {@code 'fName'}
     *
     * @param fName The name of the file to which the contents of the {@code java.lang.String} are
     * appended.  If This file doesn't already exist, it is created here.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or
     * disk operation.
     */
    public static void appendToFile(CharSequence s, String fName) throws IOException
    {
        File f = new File(fName);
        if (! f.exists()) f.createNewFile();
        Files.write(Paths.get(fName), s.toString().getBytes(), StandardOpenOption.APPEND);
    }


    // ********************************************************************************************
    // load File (as String's}
    // ********************************************************************************************


    /** Convenience Method.  Invokes {@link #loadFileToString(String)} */
    public static StringBuffer loadFileToStringBuffer(String fName) throws IOException
    { return (new StringBuffer()).append(loadFileToString(fName)); }

    /** Convenience Method.  Invokes {@link #loadFileToString(String)} */
    public static StringBuilder loadFileToStringBuilder(String fName) throws IOException
    { return (new StringBuilder()).append(loadFileToString(fName)); }

    /**
     * This will load the entire contents of a text-file on disk to a single
     * {@code java.lang.String}
     * 
     * <BR /><BR /><B><SPAN STYLE='color: red;'>TRUNCATES TRAILING ZEROES:</B></SPAN> Some of the
     * ugliest code to see is that which finds {@code 'EOF'} characters liberally inserted into a
     * simple text-file.  When reading a file (which, regardless of whether it <I>actually is a
     * text-file</I>), this method will remove any <I>trailing {@code ASCII-0}</I> characters
     * (literally, {@code char c == 0}) from the files that are read.  Finding {@code '.html'} or
     * {@code '.java'} files in which some editor (for whatever reason) has inserted 
     * {@code EOF-like} characters to the end of the text can make programming a headache.
     * 
     * <BR /><BR />Suffice it to say, the {@code String} that is returned from this method will
     * contain the last non-zero character (including CRLF, {@code '\n'} or {@code '\r'}
     * character that was read from the file.  Operating-systems do not need to have a trailing
     * zero (legacy {@code 'End-of-File'} marker) at the end of a text-file in order to interpret
     * that file.  Java {@code String's} certainly have no use for them, and when worry about
     * things like {@code equality-tests} inside Java loops, eliminating the {@code EOF}
     * character altogether is actually best.
     *
     * <BR /><BR /><B><SPAN STYLE="color: red;">FINALLY:</B></SPAN> This class has a
     * {@code static boolean} flat can shunt this behavior, and all {@code String's} returned will
     * include as many trailing zero characters at the end of the {@code String} returned by this
     * method as the Java {@code FileReader} class finds.  See {@link #TRUNCATE_EOF_CHARS}.
     *
     * @param fName the file-name of a valid text-file in the file-system
     *
     * @return The entire contents of the file as a {@code String}.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or
     * disk operation.
     */
    public static String loadFileToString(String fName) throws IOException
    {
        FileReader  fr              = new FileReader(fName);
        int         len             = (int) new File(fName).length();
        char[]      cArr            = new char[len];
        int         offset          = 0;
        int         charsRead       = 0;
        int         charsRemaining  = len;

        try
        {
            while ((offset < len) && ((charsRead = fr.read(cArr, offset, charsRemaining)) != -1))
            {
                offset          += charsRead;
                charsRemaining  -= charsRead;
            }
        }
        finally
            { fr.close(); }

        len = cArr.length;

        if (TRUNCATE_EOF_CHARS) while ((len > 0) && (cArr[len-1] == 0)) len--;

        return (len != cArr.length) ? new String(cArr, 0, len) : new String(cArr); 
    }

    /** Convenience Method.  Invokes {@link #loadFileToStream(String, boolean)} */
    public static String[] loadFileToStringArray(String fName, boolean includeNewLine)
        throws IOException
    { return loadFileToStream(fName, includeNewLine).toArray(String[]::new); }

    /**
     * This will load a file to a {@code java.lang.StringBuilder} instance.
     *
     * @param fName A file-name of a valid text-file in the file-system.
     * 
     * @param includeNewLine if this is <B>TRUE</B>, a {@code '\n'} (newline/CRLF) is appended to
     * the end of each {@code java.lang.String} read from this file.  If not, the original newline
     * characters which occur in the file, will be eliminated.
     * 
     * <BR /><BR /><B><SPAN STYLE="color: red;">MINOR NOTE:</SPAN></B> This method will make one
     * (potentially minor) mistake.  If the final character in the input-file is, itself, a 
     * new-line (if the file ends with a {@code 'CRLF' / 'CR'}), then this method should return a
     * {@code Stream<String>} that is identical to the original file.  However, <I>if the final
     * character in the file <B>is not</B> a new-line {@code '\n'}</I>, then the
     * {@code Stream<String>} that is returned will have an extra new-line appended to the last
     * {@code String} in the {@code Stream}, and the resultant {@code Stream<String>} will
     * be longer than the original file by 1 character.
     *
     * @return The entire contents of the file as a series of {@code java.lang.String} contained by
     * a {@code java.util.stream.Stream<String>}.  Converting Java {@code Stream's} to other data
     * container types is as follows:
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="STRMCNVT">
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     */
    public static Stream<String> loadFileToStream(String fName, boolean includeNewLine)
        throws IOException
    {
        FileReader              fr  = new FileReader(fName);
        BufferedReader          br  = new BufferedReader(fr);
        Stream.Builder<String>  b   = Stream.builder();
        String                  s   = "";

        try
        {
            if (includeNewLine) while ((s = br.readLine()) != null) b.add(s + "\n");
            else                while ((s = br.readLine()) != null) b.add(s);
        }
        finally
            { fr.close(); }

        return b.build();
    }

    /** Convenience Method.  Invokes {@link #loadFileToCollection(Collection, String, boolean)} */
    public static Vector<String> loadFileToVector(String fName, boolean includeNewLine)
        throws IOException
    { return loadFileToCollection(new Vector<String>(), fName, includeNewLine); }

    /**
     * This method loads the contents of a file to a {@code java.util.Collection<String>} object, 
     * where each {@code java.lang.String} in the output / returned {@code Collection} is a
     * different "line of text" from the input-file.  This is identical to using the method from
     * {@code public String[] java.lang.String 'split("\n")'} - <I>and then saving each of the
     * {@code String's} from the {@code String-array} into an element of the returned
     * {@code Collection<String>}</I>
     *
     * <BR /><BR />This method uses Java's variable-type parameter syntax to allow the programmer
     * to decide what type of {@code Collection<String>} to obtain from this method.  The standard
     * Java {@code Collection's} include: {@code TreeSet, Vector, ArrayList, HashSet}, among
     * others.  Provide a {@code new Collection<String>} by simply calling a constructor to one
     * of these classes like: {@code new Collection<String>()}.
     * 
     * <BR /><BR /><B><SPAN STYLE="color: red;">MINOR NOTE:</SPAN></B> This method will make one
     * (potentially minor) mistake.  If the final character in the input-file is, itself, a 
     * new-line (if the file ends with a {@code 'CRLF' / 'CR'}), then this method should return a
     * {@code Collection<String>} that is identical to the original file.  However, <I>if the final
     * character in the file <B>is not</B> a new-line {@code '\n'}</I>, then the
     * {@code Collection<String>} that is returned will have an extra new-line appended to the last
     * {@code String} in the {@code Collection}, and the resultant {@code Collection<String>} will
     * be longer than the original file by 1 character.
     *
     * @param collectionChoice This must be an instance of a class that extends Java's
     * base {@code class Collection<String>} - <I>using {@code 'String'} as the generic-type
     * parameter.</I>  It will be populated with the lines from a text-file using the
     * {@code Collection.add(String)} method.
     *
     * @param fName the file-name of a valid text-file on the file-system.
     *
     * @param includeNewLine if this is <B>TRUE</B>, a {@code '\n'} (newline/CRLF) is appended to
     * the end of each {@code java.lang.String} read from this file.  If not, the original newline
     * characters which occur in the file, will be eliminated.
     *
     * @return An identical reference to the reference passed to parameter
     * {@code 'collectionChoice'}
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     */
    public static <T extends Collection<String>> T loadFileToCollection
        (T collectionChoice, String fName, boolean includeNewLine)
        throws IOException
    {
        FileReader      fr  = new FileReader(fName);
        BufferedReader  br  = new BufferedReader(fr);
        String          s   = "";

        try
        {
            if (includeNewLine) while ((s = br.readLine()) != null) collectionChoice.add(s + "\n");
            else                while ((s = br.readLine()) != null) collectionChoice.add(s);
        }
        finally
            { fr.close(); }

        return collectionChoice;
    }

    // ********************************************************************************************
    // Write ONE Object To File
    // ********************************************************************************************


    /** Convenience Method.  Invokes {@link #writeObjectToFile(Object, String, boolean)}, catches Exception. */
    public static boolean writeObjectToFileNOCNFE(Object o, String fName, boolean ZIP) throws IOException
    {
        try 
            { writeObjectToFile(o, fName, ZIP); return true; }
        catch (ClassNotFoundException cnfe)
            { return false; }
    }

    /**
     * Writes a {@code java.lang.Object} to a file for storage, and future reference.
     * <BR /><BR /><B>ALSO:</B> Though the file does not need to exist already in order for this
     * file to be written (in fact, if it does exist - <I>it will be 'over-written'</I>) the
     * directory hierarchy needs to exist, or a java {@code IOException} will occur.
     *
     * @param o An {@code Object} to be written to a file as a <I><B>"Serializable"</B></I>
     * {@code java.lang.Object}
     *
     * @param fName The name of the output file
     *
     * @param ZIP a boolean that, when <B>TRUE</B>, will cause the object's data to be compressed
     * before being written to the output file.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     *
     * @throws ClassNotFoundException This exception is thrown when the Java Virtual
     * Machine (JVM) tries to load a particular class and the specified class cannot be found in
     * the classpath.
     */
    public static void writeObjectToFile
        (Object o, String fName, boolean ZIP) 
        throws IOException, ClassNotFoundException
    {
        FileOutputStream        fos     = new FileOutputStream(fName);

        if (! ZIP)
        {
            ObjectOutputStream  oos     = new ObjectOutputStream(fos);
            oos.writeObject(o); oos.flush(); oos.close(); fos.close();
        }
        else
        {
            GZIPOutputStream    gzip    = new GZIPOutputStream(fos);
            ObjectOutputStream  oos     = new ObjectOutputStream(gzip);
            oos.writeObject(o); oos.flush(); gzip.finish(); oos.close(); fos.close();	
        }
    }


    // ********************************************************************************************
    // Write ALL Objects ToFile
    // ********************************************************************************************


    /** Convenience Method.  Invokes {@link #writeAllObjectsToFile(Iterator, String, boolean)} */
    public static void writeAllObjectsToFile(Iterable<?> i, String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    { writeAllObjectsToFile(i.iterator(), fName, ZIP); }

    /** Convenience Method.  Invokes {@link #writeAllObjectsToFile(Iterator, String, boolean)}, catches Exception. */
    public static boolean writeAllObjectsToFileNOCNFE(Iterable<?> i, String fName, boolean ZIP)
        throws IOException
    {
        try
            { writeAllObjectsToFile(i.iterator(), fName, ZIP); return true; }
        catch (ClassNotFoundException cnfe)
            { return false; }
    }

    /** Convenience Method.  Invokes {@link #writeAllObjectsToFile(Iterator, String, boolean)}, catches Exception. */
    public static boolean writeAllObjectsToFileNOCNFE(Iterator<?> i, String fName, boolean ZIP)
        throws IOException
    {
        try
            { writeAllObjectsToFile(i, fName, ZIP); return true; }
        catch (ClassNotFoundException cnfe)
            { return false; }
    }

    /**
     * Writes a series of {@code java.lang.Object} to a file for storage, and future reference.
     *
     * <BR /><BR /><B>ALSO:</B> Though the file does not need to exist already in order for this
     * file to be written (in fact, if it does exist - <I>it will be 'over-written'</I>) the
     * directory hierarchy needs to exist, or a java {@code 'IOException'} will occur.
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWSOF">
     *
     * @param i A series, {@code Collection}, or {@code List} of {@code Object's} to be written
     * to a file in <I><B>Serializable</B></I> format.
     *
     * @param fName The name of the output file
     *
     * @param ZIP a {@code boolean} that, when <B>TRUE</B>, will cause the {@code Object's} 
     * data to be compressed before being written to the output-file.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or
     * disk operation.
     *
     * @throws ClassNotFoundException This exception is thrown when the Java Virtual
     * Machine (JVM) tries to load a particular class and the specified class cannot be found in
     * the {@code CLASSPATH}.
     */
    public static void writeAllObjectsToFile(Iterator<?> i, String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    {
        FileOutputStream        fos     = new FileOutputStream(fName);

        if (! ZIP)
        {
            ObjectOutputStream  oos     = new ObjectOutputStream(fos);
            while (i.hasNext()) oos.writeObject(i.next());
            oos.flush(); oos.close(); fos.close();
        } else
        {
            GZIPOutputStream    gzip    = new GZIPOutputStream(fos);
            ObjectOutputStream  oos     = new ObjectOutputStream(gzip);
            while (i.hasNext()) oos.writeObject(i.next());
            oos.flush(); gzip.finish(); oos.close(); fos.close();	
        }
    }


    // ********************************************************************************************
    // read ONE Object From File
    // ********************************************************************************************


    /** Convenience Method.  Invokes {@link #readObjectFromFile(String, boolean)}.  Catches Exception. */
    public static Object readObjectFromFileNOCNFE(String fName, boolean ZIP) throws IOException
    {
        try 
            { return readObjectFromFile(fName, ZIP); }
        catch (ClassNotFoundException cnfe)
            { return null; }
    }

    /**
     * Reads an {@code Object} from a data-file which must contain a serialized
     * {@code java.lang.Object}.
     *
     * <DIV CLASS="EXAMPLE">{@code
     * // Create some Object for writing to the file-system, using Object Serialization
     * int[] dataArr = some_data_method();
     *
     * // It is always easier to pass 'true' to the compression boolean parameter
     * FileRW.writeObjectToFile(dataArr, "data/myDataFile.dat", true);
     *
     * ...
     *
     * // Later on, this file may be read back into the program, using this call:
     * Object o = FileRW.readObjectFromFile("data/myDataFile.dat", true);
     *
     * // This check prevents compiler-time warnings.  The Annotation "SuppressWarnings" 
     * // would also work.
     * dataArr = (o instanceof int[]) ? (int[]) o : null;
     * }</DIV>
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWSOF">
     *
     * @param fName The name of a data-file that contains a serialized {@code java.lang.Object}
     *
     * @param ZIP if this is <B>TRUE</B>, it is assumed that the data-file contains a
     * zip-compressed {@code Object}
     *
     * @return The {@code Object} that was written to the data-file.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or
     * disk operation.
     *
     * @throws ClassNotFoundException This exception is thrown when the Java Virtual
     * Machine (JVM) tries to load a particular class and the specified class cannot be found
     * in the {@code CLASSPATH}.
     */
    public static Object readObjectFromFile(String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    {
        FileInputStream         fis     = new FileInputStream(fName);
        ObjectInputStream       ois     = ZIP   ? new ObjectInputStream(new GZIPInputStream(fis))
                                                : new ObjectInputStream(fis);
        Object                  o;

        try 
            { o = ois.readObject(); }
        finally
            { fis.close(); }

        return o;
    }

    /** Convenience Method.  Invokes {@link #readObjectFromFile(String, Class, boolean)}.  Catches Exception. */
    public static <T> T readObjectFromFileNOCNFE(String fName, Class<T> c, boolean ZIP)
        throws IOException
    {
        try
            { return readObjectFromFile(fName, c, ZIP); }
        catch (ClassNotFoundException cnfe)
            { return null; }
    }

    /**
     * Reads an {@code Object} from a data-file which must contain a serialized
     * {@code java.lang.Object}.
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWSOF">
     *
     * @param fName The name of a data-file that contains a serialized {@code java.lang.Object}
     *
     * @param c This is the type of the {@code Object} expecting to be read from disk.  A value
     * for this parameter can always be obtained by referencing the {@code static} field
     * {@code '.class'} which is attached to <I>every object</I> in java.
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWCT">
     * 
     * @param ZIP if this is <B>TRUE</B>, it is assumed that the data-file contains a zip-compressed
     * {@code Object}
     *
     * @return The {@code Object} that was read from the data-file.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     *
     * @throws ClassNotFoundException This exception is thrown when the Java Virtual
     * Machine (JVM) tries to load a particular class and the specified class cannot be found in
     * the {@code CLASSPATH}.
     */
    public static <T> T readObjectFromFile(String fName, Class<T> c, boolean ZIP)
        throws IOException, ClassNotFoundException
    {
        Object o = readObjectFromFile(fName, ZIP);

        if (o == null)          return null;
        if (c.isInstance(o))    return c.cast(o);

        throw new ClassNotFoundException(
            "Although an object was indeed read from the file you have named [" + fName + "], " +
            "that object was not an instance of [" + c.getName() + "], " + 
            "but rather of [" + o.getClass().getName() + "]"
        );
    }


    // ********************************************************************************************
    // read ALL OBJECTS FromFile
    // ********************************************************************************************


    /** Convenience Method.  Invokes {@link #readAllObjects(Class, Collection, String, boolean)}. */
    public static Vector<Object> readAllObjectsToVector(String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    { return readAllObjects(Object.class, new Vector<Object>(), fName, ZIP); }

    /** Convenience Method.  Invokes {@link #readAllObjects(Class, Collection, String, boolean)}. */
    public static <T> Vector<T> readAllObjectsToVector(Class<T> objType, String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    { return readAllObjects(objType, new Vector<T>(), fName, ZIP); }

    /**
     * Reads all {@code Object's} found inside a data-file.  This data-file should contain only
     * java-serialized {@code java.lang.Object's}.
     *
     * @param objType <EMBED CLASS="external-html" DATA-FILE-ID="FRWOBJTYPE">
     *
     * @param collection This should be the desired {@code Collection<E>} that the programmer
     * would like be populated with the instances of type {@code 'objType'} read from file
     * {@code 'fName'}.  Variable-Type parameter {@code 'E'} needs to be equal-to or an 
     * ancestor of {@code 'objType'}
     *
     * @param fName The name of a data-file that contains serialized {@code Object's}
     *
     * @param ZIP if this is <B>TRUE</B>, it is assumed that the data-file contains zip-compressed
     * objects
     *
     * @return A reference to the {@code Collection} that was passed to this method.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     */
    public static <T, U extends Collection<T>> U readAllObjects
        (Class<T> objType, U collection, String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    {
        Object                  o       = null;
        FileInputStream         fis     = new FileInputStream(fName);
        ObjectInputStream       ois     = ZIP   ? new ObjectInputStream(new GZIPInputStream(fis))
                                                : new ObjectInputStream(fis);

        try
        {  
            while ((o = ois.readObject()) != null)

                if (objType.isInstance(o))
                    collection.add(objType.cast(o));

                else throw new ClassNotFoundException(
                    "At least one of the objects in the serialized object file [" + fName + "], " +
                    "was not an instance of [" + objType.getName() + "], " +
                    "but rather [" + o.getClass().getName() + "]"
                );
        } 
        catch (EOFException eofe)
            { }
        finally
            { fis.close(); }

        return collection;
    }

    /** Convenience Method.  Invokes {@link #readAllObjectsToStream(Class, String, boolean)}. */
    public static Stream<Object> readAllObjectsToStream(String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    { return readAllObjectsToStream(Object.class, fName, ZIP); }

    /**
     * Reads all objects found inside a data-file.  This data-file should contain only
     * java-serialized {@code Object's}.
     *
     * @param fName The name of a data-file that contains the serialized {@code Object's}
     *
     * @param objType This is the type of the {@code Object's} expecting to be read from disk.  A value
     * for this parameter can always be obtained by referencing the static field {@code '.class'}
     * which is attached to <I>every {@code Object}</I> in java.  For instance, to read a 
     * data-file containing a series of {@code Date} instances, use {@code Date.class} as the
     * value to pass to this parameter.
     *
     * @param ZIP if this is <B>TRUE</B>, it is assumed that the data-file contains zip-compressed
     * {@code Object's}
     *
     * @return A {@code Stream<T>} of all {@code Object's} found in the data-file.  Converting
     * Java {@code Stream's} to other data container types is as follows:
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="STRMCNVTT">
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     *
     * @throws ClassNotFoundException This exception is thrown when the Java Virtual
     * Machine (JVM) tries to load a particular class and the specified class cannot be found in
     * the classpath.
     */
    public static <T> Stream<T> readAllObjectsToStream(Class<T> objType, String fName, boolean ZIP)
        throws IOException, ClassNotFoundException
    {
        Stream.Builder<T>       b       = Stream.builder();
        Object                  o       = null;
        FileInputStream         fis     = new FileInputStream(fName);
        ObjectInputStream       ois     = ZIP   ? new ObjectInputStream(new GZIPInputStream(fis))
                                                : new ObjectInputStream(fis);

        try
        {
            while ((o = ois.readObject()) != null)

                if (objType.isInstance(o)) b.accept(objType.cast(o));

                else throw new ClassNotFoundException(
                    "At least one of the objects in the serialized object file [" + fName + "], " +
                    "was not an instance of [" + objType.getName() + "], " +
                    "but rather [" + o.getClass().getName() + "]"
                );
        }
        catch (EOFException eofe)
            { }
        finally
            { fis.close(); }

        return b.build();
    }


    // ********************************************************************************************
    // Base-64 Read / Write Stuff (Text File)
    // ********************************************************************************************


    /**
     * Uses Java's {@code Object} serialization mechanism to serialize a {@code java.lang.Object},
     * and then uses the {@code Base64 String-MIME Encoding} system, also provided by java, to
     * convert the {@code Object} into a text-safe {@code java.lang.String} that may be viewed,
     * e-mailed, written to a web-page, etc.
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWSOF">
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWEX01">
     *
     * @param o This may be any serializable {@code java.lang.Object} instance.  It will be written
     * to a text-file after first serializing the {@code Object}, and then next converting the
     * serialized data-bits to MIME-safe encoded text.
     *
     * @param fileName The fileName that will be used to save this {@code Object} as a text-file.
     */
    public static void writeObjectToTextFile(Object o, String fileName)
        throws IOException
    { FileRW.writeFile(StringParse.objToB64MimeStr(o), fileName); }

    /**
     * This will read a java serialized, and MIME-Converted, MIME-Safe {@code java.lang.String}
     * from a text file and return the {@code Object} that it represented
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWSOF">
     *
     * @param fileName The name of the file containing the MIME-Encoded Serialized
     * {@code java.lang.Object}.
     *
     * @return The {@code Object} that had been encoded into the text-file.
     */
    public static Object readObjectFromTextFile(String fileName) throws IOException
    { return StringParse.b64MimeStrToObj(loadFileToString(fileName)); }

    /** Convenience Method.  Invokes {@link #readObjectFromTextFile(String, Class)}.  Catches Exception. */
    public static <T> T readObjectFromTextFileNOCNFE(String fileName, Class<T> c)
        throws IOException
    {
        try
            { return readObjectFromTextFile(fileName, c); }
        catch (ClassNotFoundException cnfe)
            { return null; }
    }

    /**
     * This will read a java serialized, and MIME-Converted, MIME-Safe {@code java.lang.String}
     * from a text file and return the {@code Object} that it represented
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWSOF">
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWEX01">
     *
     * @param fileName The name of the file containing the MIME-Encoded Serialized
     * {@code java.lang.Object}.
     *
     * @param c This is the type of the {@code Object} expecting to be read from disk.  A value
     * for this parameter can always be obtained by referencing the {@code static} field
     * {@code '.class'}, which is attached to <I>every {@code Object}</I> in java.
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="FRWCT">
     *
     * @return The {@code Object} that had been encoded into the text-file.
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or disk
     * operation.
     *
     * @throws ClassNotFoundException This exception is thrown when the Java Virtual
     * Machine (JVM) tries to load a particular class and the specified class cannot be found in
     * the {@code CLASSPATH}.
     */
    public static <T> T readObjectFromTextFile(String fileName, Class<T> c)
        throws IOException, ClassNotFoundException
    { 
        Object o = StringParse.b64MimeStrToObj(loadFileToString(fileName));

        if (o == null)          return null;
        if (c.isInstance(o))    return c.cast(o);

        throw new ClassNotFoundException(
            "Although an object was indeed read from the file you have named [" + fileName + "], " +
            "that object was not an instance of [" + c.getName() + "], " + 
            "but rather of [" + o.getClass().getName() + "]"
        );
    }


    // ********************************************************************************************
    // Object Input & Object Output Streams
    // ********************************************************************************************


    /**
     * Creates a simple {@code ObjectInputStream} - usually if multiple {@code Object's} have been
     * written to a single file.  It was better practice to put {@code Object's} in a
     * {@code java.util.Vector}, and write one {@code java.util.Vector} during serialization.
     * This, eventually, can became inadequate when downloading large numbers of HTML results,
     * where the need to write a large data-file (intermittently - by saving intermediate results)
     * is needed.
     *
     * @param fName This is the file-name of the data-file where the serialized {@code Object's}
     * have been stored.
     *
     * @param ZIP If this is set to <B>TRUE</B>, the data will be de-compressed.
     *
     * @return A java {@code ObjectInputStream}
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system
     * or disk operation.
     */
    public static ObjectInputStream getOIS(String fName, boolean ZIP) throws IOException
    {
        return ZIP
            ? new ObjectInputStream(new GZIPInputStream(new FileInputStream(new File(fName))))
            : new ObjectInputStream(new FileInputStream(new File(fName))); 
    }

    /**
     * Creates a simple {@code ObjectOutputStream} - usually if multiple {@code Object's} need
     * to be written to a single file.  It was better practice to put {@code Object's} in a
     * {@code java.util.Vector}, and write one {@code java.util.Vector} during serialization.
     *
     * @param fName This is the file-name of the data-file where the serialized {@code Object's}
     * will be stored.
     *
     * @param ZIP If this is set to <B>TRUE</B>, the data will be compressed.
     *
     * @return A java {@code ObjectInputStream}
     *
     * @throws IOException If an I/O error has occurred as a result of the file-system or
     * disk operation.
     */
    public static ObjectOutputStream getOOS(String fName, boolean ZIP) throws IOException
    {
        return ZIP
            ? new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream(new File(fName))))
            : new ObjectOutputStream(new FileOutputStream(new File(fName))); 
    }


    // ********************************************************************************************
    // Copy, Move, Delete
    // ********************************************************************************************


    /**
     * This method will perform a byte-for-byte copy of a file from one location to another.
     *
     * @param inFileName The name of the input-file.  It will be byte-for-byte copied to an output
     * file-name.
     *
     * @param outFileOrDirName The name of the output-file, or the name of the directory where the
     * file shall be moved.  If this file already exists <I>and it is a file, not a directory</I>,
     * it will be over-written.  If parameter {@code 'outFileOrDirName'} names a directory - <I>due
     * to having an ending {@code File.separator}</I>, <B>but</B> does not appear to name
     * directorie(s) that exist, this method will throw a {@code FileNotFoundException}.  However,
     * if parameter {@code 'createDirsIfNotExist'} is set to <B>TRUE</B>, <B>even if</B> parameter
     * {@code 'outFileOrDirName'} names a directory (by virtue of the fact that it ends with the
     * {@code File.separator String}) then this method will create the directory tree-structure
     * using the standard Java's {@code File.mkdirs()} method.
     *
     * <BR /><BR /><B><SPAN STYLE="color: red;">NOTE:</SPAN></B> The programmer may provide either
     * a directory-name or a file-name to parameter {@code 'outFileOrDirName'}.  If the programmer
     * has provided a directory-name instead of a file-name, the moved file will have the same name
     * as the original file ({@code 'inFileName'}) had, but it will be located in
     * {@code 'outFileOrDirName'}.
     *
     * <BR /><BR /><B><SPAN STYLE="color: red;">BEHAVIOR NOTE:</SPAN></B> The behavior of this
     * copy operation is generally / mostly the same as the standard {@code UNIX} or {@code MS-DOS}
     * commands {@code 'cp'} and {@code 'copy'} (respectively) - <I>differing only in this method's
     * ability to have directories created using {@code File.mkdirs()}</I>
     *
     * @param createDirsIfNotExist If the target output-file is situated in a directory-path that
     * does not exist, this method will throw an exception.  However, if this boolean parameter is
     * set to <B>TRUE</B> and the aforementioned situation occurs where the complete-directory tree
     * does not exist, then this method will first attempt to create the directories using
     * {@code java.io.File.mkdirs().}
     *
     * @throws SecurityException If boolean parameter {@code 'createDirsIfNotExist'} is
     * <B>TRUE</B> <I>and if</I> the directory named by parameter {@code 'outFileName'} does not
     * exist, <I>and if</I> attempting to create such a directory is not permitted by the
     * Operating-System, then this exception shall throw.
     *
     * @throws IOException For any number of fail-causes in reading or writing input stream data.
     * An explanation of all causes of such an operation is beyond the scope of this
     * method-documentation entry.
     *
     * @throws FileNotFoundException If the {@code 'inFileName'} is not found, or
     * {@code 'outFileOrDirName'} uses a directory path that doesn't exist on the file-system,
     * <B>and</B> parameter {@code 'createDirsIfNotExist'} is set to <B>FALSE</B>.
     * 
     * @throws SameSourceAndTargetException This exception will be thrown if the <CODE>Java Virtual
     * Machine</CODE> ascertains that the source and target locations point to the same physical
     * disk locations.  The classes utilized for this operation are from package
     * {@code java.nio.file.*};
     * 
     * @throws InvalidPathException If the <I>Java Virtual Machine</I> is unable to instantiate an
     * instance of {@code java.nio.files.Path} for either the {@code 'inFileName'} parameter or the
     * {@code 'outFileOrDirName'}, then this exception will be thrown.
     * 
     * @throws NoSuchFileException If, after instantiating an instance of {@code Path} for either
     * the {@code source} or the {@code target} locations, the <I>Java Virtual Machine</I> is
     * unable to build an instance of {@code Path} using the method {@code Path.toRealPath()}, then
     * this exception will throw.
     */
    public static void copyFile
        (String inFileName, String outFileOrDirName, boolean createDirsIfNotExist)
        throws IOException
    {
        File f = new File(outFileOrDirName);

        if (createDirsIfNotExist) f.mkdirs();

        if (f.isDirectory())
        {
            if (! outFileOrDirName.endsWith(File.separator))
                outFileOrDirName = outFileOrDirName + File.separator;

            outFileOrDirName = outFileOrDirName + StringParse.fromLastFileSeparatorPos(inFileName);
        }

        String inPath = Paths.get(inFileName).toRealPath().toString();
        // throws InvalidPathException
        // throws NoSuchFileException

        try
        {
            if (Paths.get(outFileOrDirName).toRealPath().toString().equals(inPath))
                throw new SameSourceAndTargetException(
                    "The Source File Name and the Target Location provided to your copyFile " +
                    "request operation appear to point to the same physical-disk location:\n" +
                    inPath
                );
        } catch (NoSuchFileException e) { }
        // NOTE: Mostly (but not always) the output file won't exist yet...  If it does not, 
        //       then we really don't need to worry about over-writing the origina file.  
        // REMEMBER: The only purpose of the above test is to make sure that the source and
        //           target are not the same (to avoid clobbering the original file)

        FileInputStream     fis     = new FileInputStream(inFileName);
        FileOutputStream    fos     = new FileOutputStream(outFileOrDirName);
        byte[]              b       = new byte[5000];
        int                 result  = 0;

        try
            { while ((result = fis.read(b)) != -1) fos.write(b, 0, result); }
        finally
            { fis.close();  fos.flush();  fos.close(); }
    }

    /** Convenience Method.  Invokes {@code java.io.File.delete()} */
    public static void deleteFiles(String... fileNames)
    { for (String fileName : fileNames) (new File(fileName)).delete(); }

    /** Convenience Method.  Invokes {@link #copyFile(String, String, boolean)}, and deletes. */
    public static void moveFile
        (String inFileName, String outFileName, boolean createDirsIfNotExist)
        throws IOException
    {
        copyFile(inFileName, outFileName, createDirsIfNotExist);
        (new File(inFileName)).delete();
    }

    /**
     * This deletes an entire directory, including any sub-directories.  It is like the UNIX
     * switch {@code -r} for the command {@code rm}, or the old Microsoft DOS Command
     * {@code 'deltree'} for deleting directories.  It simply reuses the {@code class FileTransfer}
     *
     * <BR /><BR /><B>NOTE:</B> If this method is used on a UNIX or LINUX platform, then it ought
     * to produce reults that are identical to an invocation of
     * {@code Shell.RM(directoryName, "-r")}.  However, if running on Windows, that method
     * invocation would not function because it is a LINUX native API call.  This method here is
     * actually <I><B STYLE="color: red">platform independent</B></I>.
     *
     * @param directoryName This should be a valid directory on the file-system.
     *
     * <BR /><BR /><B><SPAN STYLE="color: red">WARNING:</B></SPAN> This command <B><I>does indeed
     * delete the entire directory-tree of the named directory!</I></B>
     * 
     * @param reCreateDirectoryOnExit This parameter allows the user to create an <I>an empty
     * directory with the same name</I> as the directory that was just deleted, after all of the
     * directory's contents have been deleted.  When this parameter is passed a value of
     * <B>TRUE</B>, the equivalent of the UNIX command {@code mkdir 'directoryName'} will be 
     * executed prior to exiting this method.
     * 
     * <BR /><BR />This can be a small convenience if the user desired that the directory be 
     * cleared, rather than deleted completely.
     *
     * @param log This parameter may be null, and if it is, it will be ignored.  This shall receive
     * textual log output from the deletion process.
     *
     * <EMBED CLASS="external-html" DATA-FILE-ID="APPENDABLE">
     *
     * @return This shall return a count on the total number of deleted files.  Note that when
     * directories are deleted (not files), their deletion <I>shall not count towards</I> the
     * total returned in this integer.
     *
     * @throws IllegalArgumentException Throws if the {@code String} provided to parameter
     * {@code directoryName} does not name a valid directory on the File-System.
     */
    public static int delTree
        (String directoryName, boolean reCreateDirectoryOnExit, Appendable log)
        throws IOException
    {
        if (directoryName == null) throw new NullPointerException
            ("You have provided null to parameter 'directoryName', but this is not allowed here.");

        File f = new File(directoryName);

        if (! f.exists()) throw new IllegalArgumentException(
            "The directory name you have provided: [" + directoryName + "] was not found on the " +
            "File System.  Aborted."
        );

        if (! f.isDirectory()) throw new IllegalArgumentException(
            "The value you have provided to parameter 'directoryName' was: " + 
            "[" + directoryName + "], but unfortunately this is not the name of a directory on " +
            "the File System, but rather a file.  This is not allowed here."
        );

        // Uses class FileNode to build the directory into Java Memory.
        // It is possibly of interest to note, that if running this java code on a UNIX or
        // LINUX platform, this method should perform the exact same operation as an invocation
        // of Shell.RM(directoryName, "-r");

        FileNode fn = FileNode.createRoot(directoryName).loadTree();

        int ret = FileTransfer.deleteFilesRecursive(fn, null, null, log);

        if (reCreateDirectoryOnExit) f.mkdirs();

        return ret;
    }

    /**
     * This may read a text-file containing integer data.  If this data is a <B>Comma Separated
     * Value</B> {@code 'CSV'} text-file, please pass <B>TRUE</B> to the parameter {@code 'isCSV'}.
     * If this file contains integers that have commas between digits in groups of three (like
     * {@code '30,000'}) pleas pass <B>TRUE</B> to the parameter {@code 'hasCommasInInts'}.
     * 
     * <BR /><BR /><B STYLE="color: red">FILE FORMAT:</B> The formatting of the file is not too
     * particular.  The {@code 'flag'} parameter {@code 'isCSV'} merely requires that the
     * individual integers be separated by commas.  There may be any number of such {@code int's}
     * on a particular line, and any number of lines in the file.  Blank lines are simply ignored.
     * If {@code 'isCSV'} is set to <B>FALSE</B>, all numbers must be separated by some amount of
     * white-space.  Multiple numbers <I>may still be placed</I> on a single line (as long as
     * there is white-space between them) even if {@code 'isCSV'} is <B>FALSE</B>.
     * 
     * <BR /><BR /><B STYLE="color: red">NUMBER FORMAT:</B> The numbers in this text-file must be
     * parse-able by Java's {@code class java.lang.Integer} using the method
     * {@code Integer.parseInt(String s, int radix)}
     * 
     * @param fileName This should contain the file-name which itself contains a list of integers.
     * These integers may be separated by either a comma ({@code ','}) or a space ({@code ' '}).
     * 
     * @param hasCommasInInts It is allowed that the file named by {@code 'fileName'} contain
     * integers which use the commonly found notation of having a comma between groups of three
     * digits within an integer.  For instance the number {@code '98765'}, to a reader, is often
     * represented as {@code '98,765'}.  When this parameter is set to <B>TRUE</B>, this method
     * shall simply remove any comma that is found juxtaposed between two digits before 
     * processing any text found in the file.
     * 
     * @param isCSV If the text file named by {@code 'fileName'} is a <B>Comma Separated Value</B>
     * file, then please pass <B>TRUE</B> to this parameter.  If <B>FALSE</B> is passed here, then
     * it is mandatory that the individual numbers inside the text-file are separated by at least
     * one white-space character.
     * 
     * <BR /><BR /><B STYLE="color: red">IMPORTANT:</B> If it is decided to set both of the boolean
     * parameters to <B>TRUE</B> - <I>where the integers have commas, 
     * <B STYLE="color: red">and</B> the integers are separated by commas</I>, it is up to the
     * programmer to ensure that the individual numbers, themselves, are <I>not only</I> separated
     * by a comma, <I>but also</I> separated by a space as well.
     *
     * @param radix This is the {@code 'radix'}, which is also usually called the number's 
     * {@code 'base'} that is to be used when parsing the numbers.  Since Java's {@code class
     * java.lang.Integer} is used to perform the parse, <I>both</I> the {@code 'radix'}, <I>and</I>
     * the data found in the text-file must conform to the Java method
     * {@code Integer.parseInt(String s, int radix)}.
     * 
     * <BR /><BR /><B>NOTE:</B> This parameter may not be ignored.  If the numbers in the text-file
     * are to be interpreted as standard {@code 'decimal'} (<I>Base 10</I>) numbers, then the user
     * should simply pass the constant {@code '10'} to this parameter.
     * 
     * @return This method shall return a {@code java.util.stream.IntStream} consisting of the
     * integers that were found within the text-file provided by {@code 'fileName'}.
     * 
     * <BR /><BR /><B>NOTE:</B> An instance of {@code IntStream} is easily converted to an
     * {@code int[]} array using the method {@code IntStream.toArray()}.
     * 
     * @throws FileNotFoundException If the file named by parameter {@code 'fileName'} is not
     * found or not accessible in the file-system, then this exception will throw.
     * 
     * @throws IOException This exception throws if there are any errors that occur while
     * reading this file from the file-system.
     * 
     * @throws NumberFormatException If any of the numbers read from the text-file are not
     * properly formatted, then this exception shall throw.
     * 
     * @see StringParse#NUMBER_COMMMA_REGEX
     * @see StringParse#COMMA_REGEX
     * @see StringParse#WHITE_SPACE_REGEX
     */
    public static IntStream readIntsFromFile
        (String fileName, boolean hasCommasInInts, boolean isCSV, int radix)
        throws FileNotFoundException, IOException
    {
        FileReader              fr  = new FileReader(fileName);
        BufferedReader          br  = new BufferedReader(fr);
        IntStream.Builder       b   = IntStream.builder();
        String                  s   = "";

        while ((s = br.readLine()) != null)
        {
            // Skip blank lines.
            if ((s = s.trim()).length() == 0) continue;

            // This line simply finds String-Matches that match "Digit,Digit" and replaces
            // such matches with "DigitDigit".  After this replacement, they are parsed with ease.
            // NOTE: NUMBER_COMMMA_REGEX = Pattern.compile("\\d,\\d");
            if (hasCommasInInts)
                s = StringParse.NUMBER_COMMMA_REGEX.matcher(s).replaceAll("$1$2").trim();

            String[] numbers = isCSV
                ? StringParse.COMMA_REGEX.split(s)
                : StringParse.WHITE_SPACE_REGEX.split(s);
 
            for (String number : numbers)
                if ((number = number.trim()).length() > 0)
                    b.accept(Integer.parseInt(number, radix));
        }

        br.close();
        fr.close();
        return b.build();
    }

    /**
     * This may read a text-file containing integer data.  If this data is a <B>Comma Separated
     * Value</B> {@code 'CSV'} text-file, please pass <B>TRUE</B> to the parameter {@code 'isCSV'}.
     * If this file contains integers that have commas between digits in groups of three (like
     * {@code '30,000'}) pleas pass <B>TRUE</B> to the parameter {@code 'hasCommasInLongs'}.
     * 
     * <BR /><BR /><B STYLE="color: red">FILE FORMAT:</B> The formatting of the file is not too
     * particular.  The {@code 'flag'} parameter {@code 'isCSV'} merely requires that the
     * individual {@code long} integers be separated by commas.  There may be any number of such
     * {@code long's} on a particular line, and any number of lines in the file.  Blank lines are
     * simply ignored.  If {@code 'isCSV'} is set to <B>FALSE</B>, all numbers must be separated
     * by some amount of white-space.  Multiple numbers <I>may still be placed</I> on a single
     * line (as long as there is white-space between them) even if {@code 'isCSV'} is <B>FALSE</B>. 
     * 
     * <BR /><BR /><B STYLE="color: red">NUMBER FORMAT:</B> The numbers in this text-file must be
     * parse-able by Java's {@code class java.lang.Long} using the method
     * {@code Long.parseLong(String s, int radix)}
     * 
     * @param fileName This should contain the file-name which itself contains a list of 
     * {@code 'long'} integers.  These {@code long} integers may be separated by either a comma
     * ({@code ','}) or a space ({@code ' '}).
     * 
     * @param hasCommasInLongs It is allowed that the file named by {@code 'fileName'} contain
     * {@code long}-integers which use the commonly found notation of having a comma between groups 
     * of three digits within a {@code long} integer.  For instance the number {@code '98765'}, to
     * a reader, is often represented as {@code '98,765'}.  When this parameter is set to
     * <B>TRUE</B>, this method shall simply remove any comma that is found juxtaposed between
     * two digits before processing any text found in the file.
     *
     * @param isCSV If the text file named by {@code 'fileName'} is a <B>Comma Separated Value</B>
     * file, then please pass <B>TRUE</B> to this parameter.  If <B>FALSE</B> is passed here, then
     * it is mandatory that the individual numbers inside the text-file are separated by at least
     * one white-space character.
     * 
     * <BR /><BR /><B STYLE="color: red">IMPORTANT:</B> If it is decided to set both of the boolean
     * parameters to <B>TRUE</B> - <I>where the {@code long} integers have commas, 
     * <B STYLE="color: red">and</B> the {@code long} integers are separated by commas</I>, it is
     * up to the programmer to ensure that the individual numbers, themselves, are <I>not only</I> 
     * separated by a comma, <I>but also</I> separated by a space as well.
     * 
     * @param radix This is the {@code 'radix'}, which is also usually called the number's 
     * {@code 'base'} that is to be used when parsing the numbers.  Since Java's {@code class
     * Long} is used to perform the parse, <I>both</I> the {@code 'radix'}, <I>and</I> the data
     * found in the text-file must conform to the Java method
     * {@code Long.parseLong(String s, int radix)}.
     * 
     * <BR /><BR /><B>NOTE:</B> This parameter may not be ignored.  If the numbers in the text-file
     * are to be interpreted as standard {@code 'decimal'} (<I>Base 10</I>) numbers, then the user
     * should simply pass the constant {@code '10'} to this parameter.
     * 
     * @return This method shall return a {@code java.util.stream.LongStream} consisting of the
     * {@code long}-integers that were found within the text-file provided by {@code 'fileName'}.
     * 
     * <BR /><BR /><B>NOTE:</B> An instance of {@code LongStream} is easily converted to a
     * {@code long[]} array using the method {@code LongStream.toArray()}.
     * 
     * @throws FileNotFoundException If the file named by parameter {@code 'fileName'} is not
     * found or not accessible in the file-system, then this exception will throw.
     * 
     * @throws IOException This exception throws if there are any errors that occur while
     * reading this file from the file-system.
     * 
     * @throws NumberFormatException If any of the numbers read from the text-file are not
     * properly formatted, then this exception shall throw.
     * 
     * @see StringParse#NUMBER_COMMMA_REGEX
     * @see StringParse#COMMA_REGEX
     * @see StringParse#WHITE_SPACE_REGEX
     */
    public static LongStream readLongsFromFile
        (String fileName, boolean hasCommasInLongs, boolean isCSV, int radix)
        throws FileNotFoundException, IOException
    {
        FileReader              fr  = new FileReader(fileName);
        BufferedReader          br  = new BufferedReader(fr);
        LongStream.Builder      b   = LongStream.builder();
        String                  s   = "";

        while ((s = br.readLine()) != null)
        {
            // Skip blank lines.
            if ((s = s.trim()).length() == 0) continue;

            // This line simply finds String-Matches that match "Digit,Digit" and replaces
            // such matches with "DigitDigit".  After this replacement, they are parsed with ease.
            // NOTE: NUMBER_COMMMA_REGEX = Pattern.compile("\\d,\\d");
            if (hasCommasInLongs)
                s = StringParse.NUMBER_COMMMA_REGEX.matcher(s).replaceAll("$1$2").trim();

            String[] numbers = isCSV
                ? StringParse.COMMA_REGEX.split(s)
                : StringParse.WHITE_SPACE_REGEX.split(s);
 
            for (String number : numbers)
                if ((number = number.trim()).length() > 0)
                    b.accept(Long.parseLong(number, radix));
        }

        br.close();
        fr.close();
        return b.build();
    }


    /**
     * This may read a text-file containing floating-point data.  If this data is a <B>Comma
     * Separated Value</B> {@code 'CSV'} text-file, please pass <B>TRUE</B> to the parameter
     * {@code 'isCSV'}.  If this file contains {@code double's} that have commas between digits
     * in groups of three (like {@code '30,000,000,00'}) pleas pass <B>TRUE</B> to the parameter
     * {@code 'hasCommasInDoubles'}.
     *
     * <BR /><BR /><B STYLE="color: red">FILE FORMAT:</B> The formatting of the file is not too
     * particular.  The {@code 'flag'} parameter {@code 'isCSV'} merely requires that the
     * individual {@code double} values be separated by commas.  There may be any number of such
     * {@code double's} on a particular line, and any number of lines in the file.  Blank lines are
     * simply ignored.  If {@code 'isCSV'} is set to <B>FALSE</B>, all numbers must be separated
     * by some amount of white-space.  Multiple numbers <I>may still be placed</I> on a single
     * line (as long as there is white-space between them) even if {@code 'isCSV'} is <B>FALSE</B>. 
     * 
     * <BR /><BR /><B STYLE="color: red">NUMBER FORMAT:</B> The numbers in this text-file must be
     * parseable by Java's {@code class java.lang.Double} using the method
     * {@code Double.parseDouble(String s)}
     * 
     * @param fileName This should contain the file-name which itself contains a list of 
     * {@code 'double'} values.  These {@code double's} may be separated by either a comma
     * ({@code ','}) or a space ({@code ' '}).
     * 
     * @param hasCommasInDoubles It is allowed that the file named by {@code 'fileName'} contain
     * {@code double}-values which use the commonly found notation of having a comma between groups 
     * of three digits within a {@code double} value.  For instance the number {@code '98765.01'},
     * to a reader, can be represented as {@code '98,765.01'}.  When this parameter is set to
     * <B>TRUE</B>, this method shall simply remove any comma that is found juxtaposed between
     * two digits before processing any text found in the file.
     *
     * @param isCSV If the text file named by {@code 'fileName'} is a <B>Comma Separated Value</B>
     * file, then please pass <B>TRUE</B> to this parameter.  If <B>FALSE</B> is passed here, then
     * it is mandatory that the individual numbers inside the text-file are separated by at least
     * one white-space character.
     * 
     * <BR /><BR /><B STYLE="color: red">IMPORTANT:</B> If it is decided to set both of the boolean
     * parameters to <B>TRUE</B> - <I>where the {@code double} values have commas, 
     * <B STYLE="color: red">and</B> the {@code double} values are separated by commas</I>, it is
     * up to the programmer to ensure that the individual numbers, themselves, are <I>not only</I> 
     * separated by a comma, <I>but also</I> separated by a space as well.
     * 
     * @return This method shall return a {@code java.util.stream.DoubleStream} consisting of the
     * {@code double}-values that were found within the text-file provided by {@code 'fileName'}.
     * 
     * <BR /><BR /><B>NOTE:</B> An instance of {@code DoubleStream} is easily converted to a
     * {@code double[]} array using the method {@code DoubleStream.toArray()}.
     * 
     * @throws FileNotFoundException If the file named by parameter {@code 'fileName'} is not
     * found or not accessible in the file-system, then this exception will throw.
     * 
     * @throws IOException This exception throws if there are any errors that occur while
     * reading this file from the file-system.
     * 
     * @throws NumberFormatException If any of the numbers read from the text-file are not
     * properly formatted, then this exception shall throw.
     * 
     * @see StringParse#NUMBER_COMMMA_REGEX
     * @see StringParse#COMMA_REGEX
     * @see StringParse#WHITE_SPACE_REGEX
     */
    public static DoubleStream readDoublesFromFile
        (String fileName, boolean hasCommasInDoubles, boolean isCSV)
        throws FileNotFoundException, IOException
    {
        FileReader              fr  = new FileReader(fileName);
        BufferedReader          br  = new BufferedReader(fr);
        DoubleStream.Builder    b   = DoubleStream.builder();
        String                  s   = "";

        while ((s = br.readLine()) != null)
        {
            // Skip blank lines.
            if ((s = s.trim()).length() == 0) continue;

            // This line simply finds String-Matches that match "Digit,Digit" and replaces
            // such matches with "DigitDigit".  After this replacement, they are parsed with ease.
            // NOTE: NUMBER_COMMMA_REGEX = Pattern.compile("\\d,\\d");
            if (hasCommasInDoubles)
                s = StringParse.NUMBER_COMMMA_REGEX.matcher(s).replaceAll("$1$2").trim();

            String[] numbers = isCSV
                ? StringParse.COMMA_REGEX.split(s)
                : StringParse.WHITE_SPACE_REGEX.split(s);
 
            for (String number : numbers)
                if ((number = number.trim()).length() > 0)
                    b.accept(Double.parseDouble(number));
        }

        br.close();
        fr.close();
        return b.build();
    }
}