Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

; expected

Posted on 2005-03-28
9
Medium Priority
?
247 Views
Last Modified: 2010-03-31
Hi people,

I keep getting the following error:

ReadBytes.java:23: ';' expected
            {
            ^
1 error

On the following piece of code:

import java.io.*;
import java.util.*;

public class ReadBytes {
    public void readfile(String input_file) throws IOException {
        try {
            //create a BufferedReader using System.in
            BufferedReader brfin = new BufferedReader(new InputStreamReader(System.in));
            String input_file;
            System.out.println("Enter input file:  ");
            do {
                input_file = br.readLine();
            }
           
            //BufferedReader brfout = new BufferedReader(new InputStreamReader(System.in));
            //String output_file;
            //System.out.println("Enter output file:  ");
            //do {
              //  output_file = br.readLine();
            //}
           
            while (!input_file.matches("null"))
            { // <--------------------------------------------------------------------------Line 23
                FileInputStream fin = new FileInputStream(input_file);
                boolean eof = false;
                int count = 0;
                while (!eof) {
                    int input = file.read();
                    System.out.println(input + "   ");
                    if (input == -1)
                        {eof = true;}
                    else
                        {count ++;}
                }
            }
        }
        catch (IOException e) {}
    }
    public static void main(String[] args) throws IOException {
         ReadBytes filereader = new ReadBytes();

         //String fin = null;
         
         if (args.length > 0) {
            input_file = args[0];
         }
         else {
            printf("Error: No input file specified");
            System.exit(0);
         }
         /*if (args.length > 1) {
            output_file = args[1];
         }
         else {
            printf("Error: No output file specified");
            System.exit(0);
         }*/
         filereader.readfile(input_file);
      }
}

However.... I just cnnot see this being an error. It is extremely urgent i get this corrected.

Thank you in advance,

Andy
0
Comment
Question by:acrxx
  • 6
  • 2
9 Comments
 
LVL 15

Expert Comment

by:aozarov
ID: 13645766
while (!input_file.matches("null")) -> while (!input_file.matches("null"));
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13645775
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13645792
Actually I think you are missing the while for the first do.
replace
do {
                input_file = br.readLine();
            }

with
input_file = br.readLine();


do does not come by itself.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
aozarov earned 2000 total points
ID: 13645800
I meant: "do" does not come by itself.
This is why Java thinks the while that comes after belongs to it and is looking for the ';'
0
 

Author Comment

by:acrxx
ID: 13645805
Sorry about this.... but I am sure you donnot put a semi-colon at the end of a while statement.
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13645883
do { } while(XXX); -> always gets a semi-colon (read http://java.sun.com/docs/books/tutorial/java/nutsandbolts/while.html )
but while (XXX) { } -> don't get semi-colon.

In any case your problem is actually (as I corrected myself) do { ... } without having a while (XXX)
0
 
LVL 5

Expert Comment

by:Naeemg
ID: 13645907
here are sample codes to read and write files, will help you.

http://www.javapractices.com/Topic42.cjp

http://www.rgagnon.com/javadetails/java-0052.html
0
 

Author Comment

by:acrxx
ID: 13646046
Sorry about the previous comment.... thanks. It works... I stand corrected.

Thanks for the help
0
 
LVL 15

Expert Comment

by:aozarov
ID: 13646052
NP. :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question