Results 1 to 2 of 2
- 05-11-2008, 12:57 PM #1
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
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
- 05-12-2008, 07:05 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Is this code written by yourself? Lots of errors there. Looping syntax, arguments and many more....
Similar Threads
-
Syntax error on token "(", ; expected
By baltimore in forum AWT / SwingReplies: 3Last Post: 10-28-2009, 12:19 AM -
help with these errors
By oceansdepth in forum New To JavaReplies: 3Last Post: 04-16-2008, 04:55 PM -
Null array when passed to MouseListener
By stevemcc in forum New To JavaReplies: 2Last Post: 04-02-2008, 10:42 PM -
Errors I don't understand
By MattyB in forum New To JavaReplies: 4Last Post: 04-01-2008, 11:55 PM -
syntax error
By gabriel in forum New To JavaReplies: 3Last Post: 08-03-2007, 03:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks