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 3 of 3

Thread: File input & output

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default File input & output

    I have a java assignment due for college (I'm doing 2nd year multimedia programming) in a few weeks and Iím really struggling and donít have a clue what to do.

    The following is the first part of the assignment. I have to implement a Java application that demonstrates the use of file input/output and exception handling. my application should allow the user to enter data about some entity that is stored in a data file. My application should be able to read data from a data file, and to store that data in a set of objects.

    The following is what I have already. A lot of it is probably wrong, and I don't know what to do next.


    BookTest.java

    package books;
     
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.PrintWriter;
    import java.util.Scanner;
     
    public class BookTest {
     
    public static void main(String[] args) 
    throws FileNotFoundException
    { 
     
    File f = new File (input.txt);
     
    if ();
    {
    FileReader = new FileReader();
    }
     
    /* BufferedReader = new BufferedReader();
    PrintWriter pw = new PrintWriter(File);*/
     
    //Prompts the user for the input and output file names
    /* Scanner console = new Scanner(System.in);
    System.out.print("Input file: ");
    String inputFileName = console.next();
    System.out.print("Output file: ");
    String outputFileName = console.next();
     
    //Prompts the Scanner and PrintWriter objects for reading and writing
    File inputFile = new File(inputFileName);
    Scanner in = new Scanner(inputFile); 
    PrintWriter out = new PrintWriter(outputFileName);
    int lineNumber = 1;
    */
     
     
     
    /* while (in.hasNextLine());
    {
    String line = in.nextLine();
    out.println("/* " + lineNumber + " * " + line);
    }
    in.close();
    out.close(); */
     
    }
    }

    Books.java

    package books;
     
    public class Books {
     
    private String title;
    private String authorFName;
    private String authorLName;
    private double price; 
    }

    I would really appreciate it if anyone could help me please. Thank you.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,069
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: File input & output

    what to do next
    Make a list of what the program is supposed to do. What things in the assignment does it do now?
    What remains to be done?

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

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: File input & output

    Are you in Iadt? Hahaha, I have the same problem <3

Similar Threads

  1. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  2. Input output file help
    By peteyfresh12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 2nd, 2011, 07:44 AM
  3. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2010, 08:34 PM
  4. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 06:26 PM
  5. printing output to console & to a text file at the same time...
    By prasanna in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: August 26th, 2009, 03:43 AM