Results 1 to 15 of 15
- 07-03-2010, 01:34 AM #1
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
Need help debugging this file parsing program I am writing
Well I wrote this code
and this is the compiler outputJava Code:import java.io.*; public class verncommandshell { public static void main(String [] args)throws IOException { int i = 0; BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); File commandfile; try//reads in the command txt file and stores it in an array { commandfile = new File(commands.txt); commandreader = new FileReader(commandfile); String[] commandbuffer = new Strimg[commandfile.length]; while(commandreader != -1) { commandbuffer[i] = commandreader.read(); i++; } commandreader.close(); commandfile.close(); } catch(IOException e) { e.printStackTrace(); } for(i = 0; i < commandbuffer.length; i++) { System.out.print(commandbuffer[i]); } } }
I am confused on what I am doing wrong so guys help?:oJava Code:Script started on Fri 02 Jul 2010 08:14:27 PM EDT Welcome Commander system initilizing Command line interface intilized java javac verncommandshell.java verncommandshell.java:23: cannot find symbol symbol : variable commands location: class verncommandshell commandfile = new File(commands.txt); ^ verncommandshell.java:24: cannot find symbol symbol : variable commandreader location: class verncommandshell commandreader = new FileReader(commandfile); ^ verncommandshell.java:25: cannot find symbol symbol : class Strimg location: class verncommandshell String[] commandbuffer = new Strimg[commandfile.length]; ^ verncommandshell.java:25: cannot find symbol symbol : variable length location: class java.io.File String[] commandbuffer = new Strimg[commandfile.length]; ^ verncommandshell.java:26: cannot find symbol symbol : variable commandreader location: class verncommandshell while(commandreader != -1) ^ verncommandshell.java:28: cannot find symbol symbol : variable commandreader location: class verncommandshell commandbuffer[i] = commandreader.read(); ^ verncommandshell.java:31: cannot find symbol symbol : variable commandreader location: class verncommandshell commandreader.close(); ^ verncommandshell.java:32: cannot find symbol symbol : method close() location: class java.io.File commandfile.close(); ^ verncommandshell.java:39: cannot find symbol symbol : variable commandbuffer location: class verncommandshell for(i = 0; i < commandbuffer.length; i++) ^ verncommandshell.java:41: cannot find symbol symbol : variable commandbuffer location: class verncommandshell System.out.print(commandbuffer[i]); ^ 10 errors Command line interface intilized exit Script done on Fri 02 Jul 2010 08:14:52 PM EDTYou know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
- 07-03-2010, 02:19 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You've not initialize commands variable in your code before use. Is this the complete code you've written?
- 07-03-2010, 03:35 AM #3
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
I thought I can't initialize it that as it is the name of a .txt file that I am parsing and loading into an array. Can you show me an example of or a link to some better source than the lecture notes I am using then? Thanks a lot guys
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
- 07-03-2010, 04:01 AM #4
Is it supposed to be a String?new File(commands.txt);
new File("commands.txt");
- 07-03-2010, 04:18 AM #5
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
No at least I don't think so, here is what I was working off of:
Java Code:package Files13; import java.io.*; public class Ex132b { /** Kyle Sponable Ex 13-2b This program will output to a file using characted streams */ public static void main(String[] args)throws IOException { InputStream is; OutputStream os; int value; String fout, fin; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); File f, ff; System.out.print("Enter input filename: "); fin = br.readLine(); System.out.print("Enter output filename: "); fout = br.readLine(); try { ff = new File(fin); f = new File(fout); is = new FileInputStream(ff); os = new FileOutputStream(f); //System.out.println("Enter names numbers (<ctrl>z to end: "); value = is.read(); while (value != -1) { os.write(value); value = is.read(); } is.close(); os.close(); System.out.println("/n" + fout + " created "); } catch(IOException e) { e.printStackTrace(); } } }You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
- 07-03-2010, 04:37 AM #6
I'm confused. You've posted two different programs.
Which one are you working on?
- 07-03-2010, 04:44 AM #7
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
The first one is the one I am working on, the second one is some source from some of my old notes that I took last semester in programming class and what I am basing the file parsing off of. I was not sure if seeing that might help you guys out
Last edited by The_Sponzy_Paradox; 07-03-2010 at 04:47 AM.
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
- 07-03-2010, 12:47 PM #8
OK. How are the list of error coming?
- 07-05-2010, 01:28 AM #9
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
Here is the code as I have it now it has gotten some what better though I am still unsure what is wrong. Thanks guys Norm in particular
Java Code:import java.io.*; public class verncommandshell { public static void main(String [] args)throws IOException { int i = 0; BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); File 'commands.txt' ; try//reads in the command txt file and stores it in an array { commandfile = new File(commands.txt); commandreader = new FileReader(commandfile); String[] commandbuffer = new Strimg[commandfile.length]; while(commandreader != -1) { commandbuffer[i] = commandreader.read(); i++; } commandreader.close(); commandfile.close(); } catch(IOException e) { e.printStackTrace(); } for(i = 0; i < commandbuffer.length; i++) { System.out.print(commandbuffer[i]); } } }
Here is the output:
Java Code:Command line interface intilized javac verncommandshell.java verncommandshell.java:20: unclosed character literal File 'commands.txt' ; ^ verncommandshell.java:20: not a statement File 'commands.txt' ; ^ verncommandshell.java:20: unclosed character literal File 'commands.txt' ; ^ verncommandshell.java:20: not a statement File 'commands.txt' ; ^ 4 errors
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
-
Where have you seen code like this as it's not Java?
To declare any variable you need a type name, such as File, followed by a variable name, but this can't be enclosed in single quotes. If you want to declare and initialize a variable, then you need the above and set it equal to something that returns a File object such as a constructor, for e.g.,Java Code:File 'commands.txt' ;
Java Code:File myFile = new File("myDirectory/mySubdirectory/FileName.txt");
What are you trying to do here, create a new File that is associated with a File on the disk called "commands.txt"?
- 07-07-2010, 04:36 AM #11
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
Well I fixed everything but one last error. And I am not sure, I declared a String array but I cannot insert the tokens into the string array
here is the code
error is:Java Code:import java.io.*; public class verncommandshell { public static void main(String[] args)throws IOException { int i = 0; BufferedReader br = new BufferedReader (new InputStreamReader(System.in)); File commandfile = new File(commands.txt");//change later FileReader fr = new FileReader(commandfile); StreamTokenizer st = new StreamTokenizer(fr); String[] commandbuffer = new String[(int)commandfile.length()];//length of the file try//reads in the command txt file and stores it in an array { while(!st.TT_EOF)//while token is not the EOF { commandbuffer[i] = (st.nextToken()); //error i++; } } catch(IOException e) { e.printStackTrace(); } for(i = 0; i < commandbuffer.length; i++)//going to go away here for testing only { System.out.print(commandbuffer[i] + "\n" ); } } }
Java Code:verncommandshell.java:28: incompatible types found : int required: java.lang.String commandbuffer[i] = (st.nextToken()); ^
Last edited by The_Sponzy_Paradox; 07-07-2010 at 04:38 AM.
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
- 07-07-2010, 04:45 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What your error message really talking about? Did you read it? commandbuffer is a String array and you are trying to store an int value in it (nextToken())? Can you do that?
- 07-07-2010, 05:11 AM #13
Member
- Join Date
- Mar 2010
- Location
- Troy Upstate New York USA (Not in New York City)
- Posts
- 25
- Rep Power
- 0
Yeah, that is why I am confused it should just be a string and should accept a string no problem. I never created an Int array. So I do not understand why it is looking for an Integer. It is a string cause I can convert it to an integer and it will compile.
You know that line between genius and insanity? I am told I crossed it and went around back to insanity again.
- 07-07-2010, 05:38 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Or else convert your int value to a string literal. Depends on your requirement.
- 07-07-2010, 12:49 PM #15
Similar Threads
-
writing to a excel file from java program
By priyankabhar in forum New To JavaReplies: 7Last Post: 06-04-2013, 01:00 PM -
Im writing to a file and i want to skip lines while writing to a text file.
By Broden_McDonald in forum New To JavaReplies: 1Last Post: 02-27-2010, 01:29 AM -
help with BNF Grammar program using recursive descent parsing
By carolain79@hotmail.com in forum New To JavaReplies: 1Last Post: 10-21-2009, 08:00 PM -
Due Tommorow Writing a Program Please Help
By gallimaufry in forum New To JavaReplies: 4Last Post: 10-23-2008, 03:15 AM -
Could anyone help me in debugging my Java Program.
By zoe in forum New To JavaReplies: 1Last Post: 07-31-2007, 12:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks