https://github.com/fortescarlet/mini-ini
a mini util for .ini file
https://github.com/fortescarlet/mini-ini
ini java java-8 util
Last synced: 11 months ago
JSON representation
a mini util for .ini file
- Host: GitHub
- URL: https://github.com/fortescarlet/mini-ini
- Owner: ForteScarlet
- License: apache-2.0
- Created: 2020-02-19T12:29:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-04T16:02:13.000Z (almost 6 years ago)
- Last Synced: 2025-07-11T01:03:57.746Z (11 months ago)
- Topics: ini, java, java-8, util
- Language: Java
- Size: 566 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## What is this?
This is a mini util for `.ini` file.
>My English is poor, but I still try to edit comments in English. I hope you can understand.
>
>Most come from google translation.
>
>如果你会中文,那太好了,我们能够很好的交流。或许你可以看看[中文README](./README_CN.md)
>
>and hope a star, Thanks~ ♪(´▽`)
github: https://github.com/ForteScarlet/mini-ini
gitee : https://gitee.com/ForteScarlet/mini-ini
## How to use?
First, Click the star button in the upper right corner to make some hidden content take effect. :P
### Create project
Create project with:
> version: [](https://repo1.maven.org/maven2/love/forte/mini-ini/)
Maven:
```xml
love.forte
mini-ini
${version}
```
Gradle:
```
compile group: 'love.forte', name: 'mini-ini', version: '${version}'
```
### Read ini
You can see part of the code that appears below from [Demo1](./src/test/java/com/forte/test/Demo1.java).
See [test.ini](./src/test/resources/test.ini)
```java
// Get input stream
InputStream iniInput = Demo1.class.getClassLoader().getResourceAsStream("test.ini");
// Read by default buffered reader
IniReader ir = new BufferedIniReader();
Ini ini = ir.read(iniInput);
// show
System.out.println(ini);
// to properties and show
ini.toProperties().forEach((k, v) -> {
System.out.println(k + "=" + v);
});
```
### Create/Write ini
You can see part of the code that appears below from [Demo2](./src/test/java/com/forte/test/Demo2.java).
```java
// Create an IniBuilder and
IniBuilder b = new IniBuilder()
.plusComment("this is a test ini")
.skipLine(2)
.plusSection("sec1", "this is a section")
.plusProperty("key1", "value")
.plusProperty("key2", "value")
.plusProperty("key3", "value")
.plusProperty("key4", "value")
.plusProperty("key5", "value")
.plusProperty("key6", "value")
.plusSection("sec2")
.plusProperty("key1", "value")
.plusProperty("key2", "value")
.plusProperty("key3", "value")
.plusProperty("key4", "value")
.plusProperty("key5", "value")
.plusProperty("key6", "value")
;
// Build ini
final Ini ini = b.build();
// show
System.out.println(ini);
// Write to file
ini.write(Paths.get("F:\\test3.ini"), true);
```
## Features
* `IniElement` implements the interface `java.io.Serializable`, which can be serialized. (1.1.0)
* `Ini` inherits `ArrayList`, which can be serialized and used as a list.
* `IniProperty` implements the interface `Map.Entry`.
* `IniSection` implements the interface `List`, which can be used as a list.
## Customize
You can customize (implement the interface) to achieve some additional parsing methods.
I provide some easy-to-implement (probably) interfaces to support user customization.
If you want, you can also open source your additional implementations. If you open source, you can tell me, I will show the address in the README.
some interface or abstract class:
Ini elements like `IniElement`、`BaseElement` or `IniComment`(Default implementation is `IniCommentImpl`)、`IniProperty`(Default implementation is `IniPropertyImpl`)、`IniSection`(Default implementation is `IniSectionImpl`).
Ini reader like `IniReadable`、`IniReader` or Refer to the default implementation `BufferedIniReader`.
Ini formatter like `IniFormatter`、`IniFormatterFactory`、`ElementFormatter`.
You can refer to [Demo3](./src/test/java/com/forte/test/Demo3.java).
## Attention
- This project has no additional dependencies, so you should be able to use it directly by importing the jar package.
- By default, when parsing an ini file, the content of the ini file is divided into several parts:
```ini
# comment
[section1] # comment
# comment
property_key1=property_value
property_key2=property_value
property_key3=property_value
[section2] # comment
property_key1=property_value
property_key2=property_value
property_key3=property_value
```
- By default, the rules are:
- section is wrapped by [], and there can be comments after the end.
- comment starts with `#` and can be at the beginning of a line or the end of a section.
- Property is a key-value pair under section, and cannot be followed by a comment.
## I found a bug
Oh! nice! You can tell me through the issue, or submit the bug through branch submission. try to use simple English or Chinese. Thanks.
## end
if you like this, Give me a star or a little pocket money~
if you don't, May consider helping me improve the code
Reward me:
afdian: https://afdian.net/@ForteScarlet
alipay:

wechat:

My level is limited, please understand if there are any problems.
license: Apache License 2.0