Results 1 to 2 of 2
  1. #1
    MrKP is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Angry Cannot get passed these syntax errors

    Good morning to you and I'm new to Java, but taking classes and getting to understand it better. However, this post was due a week ago and still having problems with the below code and it reads:

    Project: Modified client to send the contents of this file, from client to server through the localhost; or indicate that the files does not exist. Connection from client and server established and wanted to send an XML file and make corrections, then send it back to the server on my local machine. Could someone help me, please because this makes you not look to do any programming.

    A similar example from "Java: A Beginners Guide"

    #1:

    /* Display a .xml file
    * java ShowFile FIRST.Client-ServerFile
    */

    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.FileInputStream;

    public class ShowFile {
    private static boolean IOException;

    private static Object args;

    @SuppressWarnings("empty-statement")
    private static void main (String arg[])
    {
    int c;
    FileInputStream fin;

    // File has been specified.
    if (args.length != 1) {
    System.out.println( "Usage: ShowFile .XML");
    return;
    }
    try {
    fin = new FileInputStream(args[0]);
    } catch (FileNotFoundException exc){
    System.out.println("File Not Found");
    return;
    }
    try {
    // read bytes until EOR is encountered
    do {
    c = fin.read();
    if ( c != -1) {
    System.out.println((char) c);
    } while (c != -1); //end of file reached here
    } while (catch(IOException exc)); {

    System.out.println ("Error reading file.");
    }
    try {
    fin.close(); //filed closed
    } catch (IOException e){
    System.out.println ("Error closing file");
    }
    }

    }} // end class ShowFile

    #2:

    /* Copy a XML file
    * java CopyFile SECOND.Client-ServerFile.xml SECOND.Client-ServerFile.xml
    */

    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;

    public class CopyFile {

    private static char ShowFile;
    private static Object args;

    private static void main (String arg[])
    {

    int c;
    FileInputStream fin;
    FileOutputStream fout;
    char CopyFile;
    char[] copyFrom = {ShowFile};

    // Both files are specified above.
    if (args.length != 2) {
    System.out.println( "Usage: CopywFile From To");
    return;
    }

    //open input file
    try {
    fin = new FileInputStream(args[0]);
    } catch (FileNotFoundException exc){
    System.out.println("Input File Not Found");
    return;
    }

    //open output file
    try {
    fout = new FileOutputStream(args [1]);
    } catch (FileNotFoundException exc){
    System.out.println("Error Opening Output File");
    }

    // close output file
    try {
    fin.close();
    } catch (FileNotFoundException exc2){
    System.out.println("Error closing input file.");
    return;
    }

    //Copy File
    try {
    do {
    c = fin.read();
    if (c!= -1) {
    fout.write(c); //reads from 1 file and writes to other.
    } //reads from 1 file and writes to other.
    } while (c != -1);
    } catch (FileNotFoundException exc) {
    System.out.println ("Error");
    }

    try {
    fin.close();
    } catch (IOException exc){
    System.out.println ("Error closing input file.");
    }
    try {
    fout.close();
    } catch (IOException exc){
    System.out.println ("Error closing output file.");
    }

    } //end try
    } //end class CopyFile

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Syntax error on token "(", ; expected
    By baltimore in forum AWT / Swing
    Replies: 3
    Last Post: 10-28-2009, 01:19 AM
  2. help with these errors
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 05:55 PM
  3. Null array when passed to MouseListener
    By stevemcc in forum New To Java
    Replies: 2
    Last Post: 04-02-2008, 11:42 PM
  4. Errors I don't understand
    By MattyB in forum New To Java
    Replies: 4
    Last Post: 04-02-2008, 12:55 AM
  5. syntax error
    By gabriel in forum New To Java
    Replies: 3
    Last Post: 08-03-2007, 04:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •