Ini (.ini)
背景
-
- 配合文件格式.
- 由分段组成.
- 将字符串的键与值相关联.
- 存储操作系统和软件的配置.
- 纯文本格式.
Import 与 Export
- Import["file.ini"] 返回一个作为 Association 的 Ini 文件表示.
- Import["file","Ini"] 返回一个作为 Ini 文件的文件表示.
- Import["file.ini",elem] 返回一个 Ini 文件的特定数据表示.
- Import["file",{"Ini",elem}] 返回一个文件的特定数据表示.
- Export["file.ini",expr] 将 expr 作为 Ini 文件导出.
- 请到以下参考页面了解完整的基本信息:
-
Import, Export 从文件导入或导出到文件 CloudImport, CloudExport 从云对象导入或导出到云对象 ImportString, ExportString 从字符串导入或导出到字符串 ImportByteArray, ExportByteArray 从字节数组导入或导出到字节数组
范例
基本范例 (6)
ExportString[<|"webservers" -> <|"tomcat.server.1" -> "host1", "tomcat.server.2" -> "host2"|>|>, "Ini"]file = CreateFile[];WriteString[
file, "
[login]
user=root
password=12345"];Import[file, "Ini"]file = CreateFile[];WriteString[file, "
;An example of a Windows boot.ini
[boot loader]
timeout=40
default=multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\\WINDOWS=\"Microsoft Windows XP Professional\" /fastdetect
"];仅导入数据,作为一个 Association:
Import[file, "Ini"]Import[file, {"Ini", "AnnotatedData"}]ImportString[" key = value ", "Ini"]ImportString["; comment starting with spaces", {"Ini", "AnnotatedData"}]分段必须以字符 "[" and finish with "]" 开始:
ImportString[" [section]", "Ini"]ImportString[" ; comments", "Ini"]用 InputForm 将任意表达式转换为字符串:
ExportString[<|"Section" -> <|"quantity" -> Quantity[1, "Hours"]|>|>, "Ini"]历史
2017年引入 (11.1)