View Single Post
  #1 (permalink)  
Old 05-11-2008, 01:57 PM
MrKP MrKP is offline
Member
 
Join Date: May 2008
Posts: 1
MrKP is on a distinguished road
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
Reply With Quote
Sponsored Links