Results 1 to 5 of 5
  1. #1
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default How to import Data from Text file ??

    Hello,

    I am trying to write a program, which includes an import data option. This option is used to import information from a text file.

    The data is read from the file and objects are created and added to the student's record (The text file contains some information of the courses that the student is taking).

    So my question is, how do i import information from a text file ?? (i have absolutely no idea).
    and after they are imported, how do i create the objects in order to add them to the student's record ??

    Thanks!
    Regards,
    toiletpaper

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: How to import Data from Text file ??

    Reading files:
    - Java Practices -> Reading and writing text files
    - Reading, Writing, and Creating Files (The Java™ Tutorials > Essential Classes > Basic I/O)

    Creating objects is no different than normal: Student student = new Student(firstname, lastname, ...);
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  3. #3
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: How to import Data from Text file ??

    Quote Originally Posted by SurfMan View Post
    Reading files:
    - Java Practices -> Reading and writing text files
    - Reading, Writing, and Creating Files (The Java™ Tutorials > Essential Classes > Basic I/O)

    Creating objects is no different than normal: Student student = new Student(firstname, lastname, ...);
    Thank you !! :D

  4. #4
    toiletpaper is offline Member
    Join Date
    May 2014
    Posts
    43
    Rep Power
    0

    Default Re: How to import Data from Text file ??

    I still dont really understand how they work, could u provide some explanation, as im rly new to this stuff.

    Buffered I/O Methods for Text Files

    Charset charset = Charset.forName("US-ASCII");
    try (BufferedReader reader = Files.newBufferedReader(file, charset)) {
    String line = null;
    while ((line = reader.readLine()) != null) {
    System.out.println(line);
    }
    } catch (IOException x) {
    System.err.format("IOException: %s%n", x);
    }
    How can i use that for example ? i get tons of errors if i try to implement it into my code (.forName error, NewBuffer error, etc.)
    Last edited by toiletpaper; 05-22-2014 at 12:55 PM.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: How to import Data from Text file ??

    There is less than 15 minutes between your last two posts, try spending actual time on this in stead of immediately outsourcing your troubles. Its the only way to learn. If you can't figure it out from one resource, look for others.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. How to import(read) a data file into jtable
    By leszer in forum NetBeans
    Replies: 1
    Last Post: 06-04-2012, 05:16 AM
  2. Replies: 2
    Last Post: 03-25-2011, 02:36 PM
  3. Replies: 6
    Last Post: 12-01-2010, 05:31 AM
  4. Import data from file into a gui
    By SBL in forum AWT / Swing
    Replies: 5
    Last Post: 11-21-2009, 04:10 PM
  5. reading data from text file .. help plz
    By Thug heart in forum New To Java
    Replies: 7
    Last Post: 02-15-2009, 07:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •