Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2006, 10:05 AM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default first debug problem in my code

Hi,

I am a beginner in Java for a project but I have lots of experience in C++ and Matlab! Now I use eclipse as an environment to program. To know java and eclipse better I started with a class where I can load a txt file with. also I try to organize the code like I was used to in C++. I have two questions for my following code below:

package readOMIM;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * This program reads a text file line by line and print to the console. It uses
 * FileOutputStream to read the file.
 *
 */

class aap {
    // Objects
    File file = null;
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    DataInputStream dis = null;

    void LoadFile(String name)
    {
        File file = new File(name);
        try
        {
            fis = new FileInputStream(file);
            // Here BufferedInputStream is added for fast reading.
            bis = new BufferedInputStream(fis);
            dis = new DataInputStream(bis);
            //fis.close();
            //bis.close();
            //dis.close();
          //while (dis.available() != 0)
            {
                 // this statement reads the line from the file and print it to
                 // the console.
                // System.out.println(dis.readLine());
            }
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
    void ShowContent()
    {
        //dis.available();
// dis.available() returns 0 if the file does not have more lines.

        if (dis.available())
        {

             // this statement reads the line from the file and print it to
             // the console.
             //System.out.println(dis.readLine());
        }

    }
}
public class readOMIM {

  public static void main(String[] args) {


    aap omimsite;
    omimsite = new aap();

    omimsite.LoadFile("C:\\Documents and Settings\\hvanhaagen\\" +
                                "My Documents\\OMIM\\genemap.txt");
    omimsite.ShowContent();
  }
}

Now the compiler tells that this code is not legal because of the following statement:

if (dis.available())

I don't know why? I think it is a simple starting problem of mine! yet my second question is about the structure. I like to organize my classes with a header file like in C++. So only the declaration of a method in a class and the implementation outside. They maybe be in the same file but at the top you can see fast how the class is organized.

Thank you!
Herman


 
Old September 25th, 2006, 03:25 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to orfano
Default

haagen,

The available() method in DataInputStream class regards to the number of bytes that can be read from that stream

See javadoc
available()
          Returns the number of bytes that can be read from this input stream without blocking.

 
Old September 25th, 2006, 03:28 AM
Registered User
 
Join Date: Sep 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to orfano
Default

...continuing

Have a lootk in the BufferedReader class documentation. i guess it would be what you are looking for.

http://java.sun.com/j2se/1.4.2/docs/...redReader.html

Cheers, flavio






Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't Debug Jul-2008 code under VS2008 agemagician BOOK: Professional Microsoft Robotics Studio ISBN: 978-0-470-14107-6 1 November 7th, 2008 02:11 AM
Debug Problem monika.vasvani ASP.NET 2.0 Basics 0 June 9th, 2008 09:36 PM
debug code iceman90289 C# 2005 2 March 31st, 2008 03:39 AM
Debug problem Scootterp Access VBA 4 August 9th, 2006 10:30 AM
C++ Debug Problem junebug C++ Programming 1 February 11th, 2005 01:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.