Simple End-of-line marker help!!!

Hi. I'm writing a simple java program to basically take take 2 parameters as a source file and a target file. My program will will the Source File and make an exact duplicate of it line for line under a new file (the target file). As of right now, i have it successfully read and copy each line. However, i have one problem: I need to be able to recognize End-of-line markers so that if the very last line of the source file DOES NOT have an End-of-line marker, then it won't print an End-of-line marker. I basically am lost about how to check and recognize the End-of-line marker at all. Here's my code so far:

import java.io.*;

public class Copy
{
    /**
     * Constructor for objects of class Copy
     */
    public static void main(String[]args)
    {
        if(args.length == 2)
        {
            try
            {
                String data;
               
                String inputFile = args[0];
                FileReader inStream = new FileReader(inputFile);
                BufferedReader ins = new BufferedReader(inStream);
               
                String outputFile = args[1];
                FileWriter outStream = new FileWriter(outputFile);
                PrintWriter outs = new PrintWriter(outStream);
               
                do
                {
                    data = ins.readLine();
                    if (data != null)
                    {
                        outs.println(data);
                    }
                }   while(data != null);
               
                ins.close();
                outs.close();
            }
            catch(IOException ex)
            {
                System.out.println("--- Error: " + ex.getMessage());
                ex.printStackTrace();
                System.exit(1);
            }
            catch(NumberFormatException ex)
            {
                System.out.println(ex.getMessage());
                ex.printStackTrace();
            }
        }
        else
        {
            System.out.println("--- Error: No Parameters Entered");
            System.exit(1);            
        }
    }
}

Someone please help!! I want to be able to test for end-of-line markers but i have no clue how! Thanks to all for reading this! =)
xillu5ionzxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
If you are just doing a direct copy then use a stream class directly instead of a reader and just copy the bytes.
0
objectsCommented:
akaik it is not possible to do what you require using readLine().
0
honey_bearCommented:
use ins.ready() test is end.


import java.io.*;
public class test
{
   /**
    * Constructor for objects of class Copy
    */
   public static void main(String[]args)
   {
       if(args.length == 2)
       {
           try
           {
               String data;
               
               String inputFile = args[0];
               FileReader inStream = new FileReader(inputFile);
               BufferedReader ins = new BufferedReader(inStream);
               
               String outputFile = args[1];
               FileWriter outStream = new FileWriter(outputFile);
               PrintWriter outs = new PrintWriter(outStream);
               
               do
               {
                   data = ins.readLine();
                   if (data != null)
                   {
                            if(ins.ready())
                            outs.println(data);
                            else
                                 outs.print(data);
                   }
               }   while(data != null);
               
               ins.close();
               outs.close();
           }
           catch(IOException ex)
           {
               System.out.println("--- Error: " + ex.getMessage());
               ex.printStackTrace();
               System.exit(1);
           }
           catch(NumberFormatException ex)
           {
               System.out.println(ex.getMessage());
               ex.printStackTrace();
           }
       }
       else
       {
           System.out.println("--- Error: No Parameters Entered");
           System.exit(1);            
       }
   }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.