Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Problem in FileInputStream

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem in FileInputStream

    hello all! I am very beginner in java and learning File handling. I got some error in the program given below:
    import java.io.*;
    public class FileOutputStream {

    public static void main(String[] args) throws IOException {

    //set up file and stream
    File outFile = new File("sample1.data");
    FileOutputStream outStream = FileOutputStream(outFile); //Error:The constructor FileInputStream(File) is undefined
    //data to output
    byte[]byteArray = {10, 20, 30, 40, 50, 60, 70, 80};
    //write data to the stream
    outStream.write(byteArray); //Error: Create a Method read
    //output done, so close the stream
    outStream.close(); /Er/ror: Create a Method close

    }

    }

    This program is taken from some book but still error. can anyone explain the error??

    Thanks
    Ranjeet


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Problem in FileInputStream

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    The primary problem is that you've named your class, FileOutputStream, the same as an existing SE class. Give your program another name.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem in FileInputStream

    FileOutputStream outStream = FileOutputStream(outFile); //Error:The constructor FileInputStream(File) is undefined
    I don't understand the error message. It refers to Input but the code has Output

    Can you copy the exact and full text of the compiler's error message and paste it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Problem in FileInputStream

    import java.io.*;
    public class FileOutputStream {
     
    public static void main(String[] args) throws IOException {
     
            //set up file and stream
             File outFile = new File("sample1.data");
             FileOutputStream outStream = FileOutputStream(outFile); //Error:The constructor FileInputStream(File) is undefined
             //data to output
              byte[]byteArray = {10, 20, 30, 40, 50, 60, 70, 80};
             //write data to the stream
             outStream.write(byteArray); //Error: Create a Method read
             //output done, so close the stream
              outStream.close();    //Error: Create a Method close
     
          }
     
    }


    --- Update ---

    sorry for not writing code in proper way...actually i m using this forum first time.....

    --- Update ---

    I changed the name of class still setting one error in
    FileOutputStream outStream =  FileOutputStream(outFile);

    error:The method FileOutputStream(File) is undefined for the type FileOutStreamTest

    Quote Originally Posted by ranjeet270 View Post
    import java.io.*;
    public class FileOutputStream {
     
    public static void main(String[] args) throws IOException {
     
            //set up file and stream
             File outFile = new File("sample1.data");
             FileOutputStream outStream = FileOutputStream(outFile); //Error:The constructor FileInputStream(File) is undefined
             //data to output
              byte[]byteArray = {10, 20, 30, 40, 50, 60, 70, 80};
             //write data to the stream
             outStream.write(byteArray); //Error: Create a Method read
             //output done, so close the stream
              outStream.close();    //Error: Create a Method close
     
          }
     
    }


    --- Update ---

    sorry for not writing code in proper way...actually i m using this forum first time.....
    Quote Originally Posted by GregBrannon View Post
    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

    The primary problem is that you've named your class, FileOutputStream, the same as an existing SE class. Give your program another name.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Problem in FileInputStream

    Please post the current code and the full text of the error message.
    Error messages should show the line number where the error happened.

    One error I see is the keyword new is missing where the code is trying to create an instance of a class.
    = FileOutputStream(outFile);
    That syntax looks like a call to a method named: FileOutputStream()
    error:The method FileOutputStream(File)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Catch block problem. Please fix my problem.
    By damnitsme in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 3rd, 2014, 01:49 AM
  2. FileInputStream is not saving the excel document.
    By loui345 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: July 17th, 2013, 02:00 PM
  3. Replies: 1
    Last Post: February 13th, 2013, 09:07 AM
  4. Replies: 3
    Last Post: January 5th, 2012, 01:44 AM
  5. [SOLVED] [Problem] imports javax.swing problem
    By Brollie in forum AWT / Java Swing
    Replies: 8
    Last Post: July 5th, 2009, 07:59 AM

Tags for this Thread