🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #3170

Re: ini file class

#3170
From: Position
Date: Thu, 09 Apr 1998 00:00
71 lines
2758 bytes


Richard Bakker wrote:

> Can anyone tell me how to handle ini-files?
>
> I need a class that does the work for me. (Just as TInifile in pascal.)
>
> Richard

Here's some non-generic sample code that I sucked from one of my programs.
It only handles reading an INI file. Should you need to write to an INI
file, you are probably better off with the java.util.Properties class.

-Bill Bercik

   static void readIniFile(){
    String workingDirectory =
System.getProperties().getProperty("user.dir");
    File iniFile = new File(workingDirectory,"resortdet.ini");
    if (iniFile.exists()){
      try {
        FileInputStream in = new FileInputStream(iniFile);
        BufferedReader fis = new BufferedReader(new InputStreamReader(in));

        String s = "";
        int count = 0;
        while ((s = fis.readLine()) != null) {
          int idx = s.indexOf("=");
          if (idx != -1) {
            String front = s.substring(0, idx);
            String back="";
            try{
              back = s.substring(idx+1);
            } catch (Exception e){
               back = "??";
            }
            count++;
            if (front.equalsIgnoreCase("mailHost")){
              mailHost = back;
            }
            if (front.equalsIgnoreCase("dBaseDriver")){
              dBaseDriver = back;
            }
            if (front.equalsIgnoreCase("dBasePassword")){
              dBasePassword = back;
            }
            if (front.equalsIgnoreCase("dBaseUrl")){
              dBaseUrl = back;
            }
            if (front.equalsIgnoreCase("dBaseUsername")){
              dBaseUsername = back;
            }
            if (front.equalsIgnoreCase("fromEmail")){
              fromEmail = back;
            }
            if (front.equalsIgnoreCase("printerFontSize")){
              printerFontSize = Integer.parseInt(back);
            }
            if (front.equalsIgnoreCase("lookAndFeel")){
              lookAndFeel = Integer.parseInt(back);
            }
          }
        }
        in.close();
      }catch(IOException e) {
        e.printStackTrace();
      }
    }
  }
Technical Details
Message-ID: <352D3990.1A9312B6@pedalplanet.org>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <6gg14o$8a6$2@news.Zwolle.NL.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1089d0,166c16540486de8
X-Google-Attributes: gid1089d0,public
From: Position <positions@pedalplanet.org>
Subject: Re: ini file class
Date: 1998/04/09
Message-ID: <352D3990.1A9312B6@pedalplanet.org>
X-Deja-AN: 342530932
Content-Transfer-Encoding: 7bit
References: <6gg14o$8a6$2@news.Zwolle.NL.net>
Mime-Version: 1.0
To: Richard Bakker <richard.bakker@brite.nl>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.api