Results 1 to 2 of 2

Thread: .ini files...

  1. #1
    Camzie is offline Member
    Join Date
    Nov 2009
    Location
    Pretoria
    Posts
    12
    Rep Power
    0

    Default .ini files...

    Hi there

    I need help!!!!

    How do you read from an .ini file by using a java socket?????

    Will appreciate it
    Camzie

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    6

    Default

    well, a socket has an input stream.
    an input stream can be read with a reader.
    a reader supports reading line-oriented things.

    an ini file has two types of lines, the [header] in the square bracket thing, and the key=value kind of thing.

    in an ideal case one would create a grammar, such as using ANTLR or jflex that produces tokens from scanning the input text, kind of like a regular expression.

    in a pinch, I guess you could read a line from the reader that is wrapping the input stream from the socket and do simple "if line starts with [ " then consider it to be the start of a section, else if it starts with ";" or "#" or is empty, then consider it a comment or white space and then ignore it. otherwise read the line, split it on the "=", the stuff on the left hand side is the key name, the stuff on the right hand side is the value. Then take, this key/value, and stuff it into the contents for the current 'section'.

    Conceptually, the data storage for an in-memory view of the contents of an .ini file might look like.

    Java Code:
    Map<String, Map<String, String>> iniFileContents;
    Where the outer map stores the 'section' name, and the inner map stores each key-value entry within the map.

    But, this kind of thing has already been figured out, back in 2004. See the posting on CodeProject site. CodeProject: An Enhanced INI File Class for Java. Free source code and programming help

Similar Threads

  1. working with files (text files)
    By itaipee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 12:38 PM
  2. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 04:20 PM
  3. Text and image files within jar files
    By erhart in forum Advanced Java
    Replies: 8
    Last Post: 01-19-2008, 05:43 AM
  4. how to convert mpeg files to .wav files
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:14 AM
  5. convert xls files into pdf files
    By bbq in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 04:56 AM

Posting Permissions

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