Creating an ini file java




















We can pass the file name or absolute path or relative path as an argument in the File class object. For a non-absolute path, File object tries to locate the file in the current directory.

The following example creates a new, empty text file. The first run creates music. We can create any type of file by changing the file extension only. A file Output stream writes data to a file. Java FileOutputStream class also provide support for files. It belongs to the java. It stores the data into bytes. We use FileOutputStream class when we need to write some data into the created file. The FileOutputStream class provides a constructor to create a file. The signature of the constructor is:.

It also provides support for files. The nio package is buffer-oriented. The createFile method is also used to create a new, empty file. We don't need to close the resources when using this method. It is an advantage. The following example also creates a new, empty file.

We create a Path instance using a static method in the Paths class java. Paths named Paths. Assuming we have an ini file myinifile. It's pretty easy to obtain the values using the Ini4j interface. Basically, you need to instantiate a Wini class that expects as first argument a File class with the path of the ini file that you want to parse, the returned object will allow you to interact with the API of this library, making it pretty easy to obtain the values from it.

The method that you need to use from the object is the get, this method expects up to 3 arguments:. To change the value of a property within a section, use method put from the instance of the Wini class. This method expects up to 3 arguments:. No problem, though I wouldn't say it's bad. If you need to read an INI file created by someone else, or generate one for another program, use ini4j.

If you're creating your own INI file that contains stuff related to your Java program, you should use Properties.

That way, you don't have to add INI support. I updated my code with an example on sections with Properties — hotforfeature. UserID" ;" in my code but the return value is null. What does your properties file look like? INI files on other operating systems which is not correct. You won't find files with extension. For example check samba configuration format, or any another linux system config files. Show 2 more comments.

Sign up or log in Sign up using Google. Sign up using Facebook. I'm making an application in which I want to make. Tim Moores. Saloon Keeper. Stephan van Hulst. I assume you have a web application that the user logs in to. Do you have a good reason you want to use ini files, and not just a user settings table in a database?

If your application runs in a browser, it's a web application. You can't interact with the file system easily from a browser. You can interact with a file-system from your application's back-end, but that begs the question why you're not using a database instead. Jesper de Jong. Java Cowboy.



0コメント

  • 1000 / 1000