JAVA Read an input CSV file containing addresses using a Sca
JAVA
Read an input CSV file containing addresses using a Scanner object. Don\'t redirect from stdin, read directly from the file. Here are two sample lines from a mailing list:
link for CSV file
http://www.filedropper.com/addresses_1
Obtain the input file using a JFileChooser dialog. See the UseFileChooser Example in the input-output examples file.
Here is example file
https://gist.github.com/c675546507c3881f93b6a3ec970f77aa
https://gist.github.com/3e7611603dcc9319bd524f25f24f65d7
For each line write out an address like this to the output file labels.txt:
The bar code is encoded using this table:
 In addition to encoding the 9 digits of the zip code, the bar code includes initial (i) and terminal (t) frame bars and a check sum (cs), which is 10 - the sum of the zip code digits mod 10. Thus the zip code 38141-8346 is encoded like this:
The sum of the digits is 38 and 38 % 10 is 8, so the check sum is 10 - 8 = 2. The initial and terminal frame bars are always |.
 
 Note: If the sum of the digit % 10 is 0, the check sum is 10 - 0 = 10, which should be replaced by 0. This can be done with an if statement, or with
See this article for more details:
http://en.wikipedia.org/wiki/POSTNET
 Write and use this method:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | 
|---|---|---|---|---|---|---|---|---|---|
| :::|| | ::|:| | ::||: | :|::| | :|:|: | :||:: | |:::| | |::|: | |:|:: | ||::: | 
Solution
import java.io.*;
public class FileCopy
 {
    //This method has reusable code, so not handling exception.
    public static void copyFile(String srcFile, String destFile)throws FileNotFoundException, IOException
    {
            FileInputStream        fis = new FileInputStream(srcFile);
            FileOutputStream   fos = new FileOutputStream(destFile);
           int i;
            while( ( i = fis.read() ) != -1)
            {
                fos.write(i);
            }
           System.out.println(\"Data has written\");
    }
 }
 class Test
 {
    public static void main(String[] args)
    {
        //It is user application, so it must handled exceptions to print user understandable exception messages
       
        try
        {  
            FileCopy.copyFile(args[0], args[1]);
        }
        catch(ArrayIndexOutOfBoundsException aeiob)
        {
            System.out.println(\"Error: Please pass source and destination file names\");
            System.out.println(\"Usage: java Test abc.txt bbc.txt\");
        }
        catch(FileNotFoundException fnfe)
        {
            System.out.println(\"Error: The given files \"+ args[0] +\" , \" + args[1] + \" are not found, make sure they are avilable in the current path\");
        }
        catch(IOException ioe)
        {
            System.out.println(\"Error: Reading or writting failed\");
            e.printStackTrace();
        }
    }
 }


