Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » InputStream not working in Eclipse for me
InputStream not working in Eclipse for me [message #788569] Thu, 02 February 2012 00:30 Go to next message
John Hanson is currently offline John HansonFriend
Messages: 2
Registered: February 2012
Junior Member
I'm not sure if eclipse is doing this but. I'm not able to do inputStreams like I've been trying to. I'm trying to run a simple program. I'm not very fond with Ecplise. I'm not sure if it is the code or the program.
I come up with these errors.

FileInputStream.open(String)line: not available[native method]
FileInputStream.<init>(File)line: not available
Scanner.<init>(File)line: not available
prog201.main(String[])line: 10

I then get a window asking me where the source is.
I go to the source and it still doesn't work .

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

class prog201
{
  public static void main (String[] args) throws IOException
  { 
    File    file = new File("myData.txt");   
    Scanner scan = new Scanner( file );     
    int num, square;

    num = scan.nextInt();
    square = num * num ;   

    System.out.println("The square of " + num + " is " + square);
  }
}

[Updated on: Thu, 02 February 2012 00:35]

Report message to a moderator

Re: InputStream not working in Eclipse for me [message #788619 is a reply to message #788569] Thu, 02 February 2012 02:11 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
On 02/01/2012 06:30 PM, John Hanson wrote:
> I'm not sure if eclipse is doing this but. I'm not able to do
> inputStreams like I've been trying to. I'm trying to run a simple
> program. I'm not very fond with Ecplise. I'm not sure if it is the code
> or the program.
> I come up with these errors.
>
> FileInputStream.open(String)line: not available[native method]
> FileInputStream.<init>(File)line: not available
> Scanner.<init>(File)line: not available
> prog201.main(String[])line: 10
>
>
What you have posted aren't errors. They appear to be part of an
exception stack trace. However, they aren't the complete stack trace,
so we can't know for sure what might be wrong.

Based on what you have included, my guess would be that the file
myData.txt cannot be found. If this is the problem, you have to make
sure that the working directory you run the program in is the same
directory that contains the file.

You can set the working directory that Eclipse uses to launch your
program on the Launch Config, Arguments tab.

> import java.util.Scanner;
> import java.io.*;
>
> class prog201
> {
> public static void main (String[] args) throws IOException
> { File file = new File("myData.txt"); // create a File object
> Scanner scan = new Scanner( file ); // connect a Scanner to the file
> int num, square;
>
> num = scan.nextInt();
> square = num * num ;
> System.out.println("The square of " + num + " is " + square);
> }
> }
Previous Topic:Save File Outside a Project?
Next Topic:Unable to run Eclipse.
Goto Forum:
  


Current Time: Wed Apr 24 17:18:08 GMT 2024

Powered by FUDForum. Page generated in 0.07350 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top