.NET框架中是否有可以读/写标准.ini文件的类:
[Section]
<keyname>=<value>
...
Run Code Online (Sandbox Code Playgroud)
Delphi有TIniFile
组件,我想知道C#是否有类似内容?
我想在php中增加最长执行时间,而不是通过更改php.ini
文件.
我想从我的php文件中增加它.
这可能吗?
我正在为Java中的遗留应用程序编写替代品.其中一个要求是旧应用程序使用的ini文件必须按原样读入新的Java应用程序.此ini文件的格式是常见的Windows样式,带有标题部分和键=值对,使用#作为注释字符.
我尝试使用Java中的Properties类,但是如果不同标头之间存在名称冲突,那么这当然不起作用.
所以问题是,读取这个INI文件并访问密钥的最简单方法是什么?
我需要使用Python3 读取,编写和创建一个INI文件.
FILE.INI
default_path = "/path/name/"
default_file = "file.txt"
Run Code Online (Sandbox Code Playgroud)
Python文件:
# Read file and and create if it not exists
config = iniFile( 'FILE.INI' )
# Get "default_path"
config.default_path
# Print (string)/path/name
print config.default_path
# Create or Update
config.append( 'default_path', 'var/shared/' )
config.append( 'default_message', 'Hey! help me!!' )
Run Code Online (Sandbox Code Playgroud)
更新的 FILE.INI
default_path = "var/shared/"
default_file = "file.txt"
default_message = "Hey! help me!!"
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用C++解析INI文件.关于什么是实现这一目标的最佳方法的任何提示?我应该使用Windows API工具进行INI文件处理(我完全不熟悉),一个开源解决方案或尝试手动解析它?
我不在乎,如果是JSON
,pickle
,YAML
,或什么的.
我见过的所有其他实现都不是向前兼容的,所以如果我有一个配置文件,在代码中添加一个新密钥,然后加载该配置文件,它就会崩溃.
有没有简单的方法来做到这一点?
Windows ini文件中是否允许注释?(...假设您正在使用GetPrivateProfileString api函数来读取它们...)
[Section]
Name=Value ; comment
; full line comment
Run Code Online (Sandbox Code Playgroud)
并且,在任何地方都有适当的.INI文件格式规范吗?
谢谢你的回复 - 但也许我不够清楚.它只是我感兴趣的Windows API调用所读取的格式.我知道其他实现允许注释,但它特别是我需要了解的MS Windows规范和实现.
我正在使用xampp
服务器进行PHP
开发,并希望编辑该php.ini
文件; 我在哪里可以找到它?
我有一个ini文件,其中包含一些示例值,如:
[Section1]
Value1 = 10
Value2 = a_text_string
Run Code Online (Sandbox Code Playgroud)
我正在尝试加载这些值并使用Boost在我的应用程序中打印它们,但我不明白如何在C++中执行此操作.
我在这个论坛中搜索,以便找到一些例子(我总是使用C,所以我在C++中不是很好)但我只找到了关于如何一次性从文件中读取值的示例.
我需要在我想要的时候只加载一个值,比如string = Section1.Value2
因为我不需要读取所有的值,而只需要读取其中的一些值.
我想加载单个值并将它们存储在变量中,以便在我的应用程序中使用它们时使用它们.
使用Boost可以做到这一点吗?
目前,我正在使用此代码:
#include <iostream>
#include <string>
#include <set>
#include <sstream>
#include <exception>
#include <fstream>
#include <boost/config.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
namespace pod = boost::program_options::detail;
int main()
{
std::ifstream s("file.ini");
if(!s)
{
std::cerr<<"error"<<std::endl;
return 1;
}
std::set<std::string> options;
options.insert("Test.a");
options.insert("Test.b");
options.insert("Test.c");
for (boost::program_options::detail::config_file_iterator i(s, options), e ; i != e; ++i)
std::cout << i->value[0] << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
但这只是读取for
循环中的所有值; 相反,我只想在需要时读取单个值,并且我不需要在文件中插入值,因为它已经用我在程序中需要的所有值写入.
在Mac OSX Mavericks使用自制软件php55每当我运行一个PHP命令时,我得到以下错误消息(一切运行正常它只是烦人)
PHP Warning: Module 'intl' already loaded in Unknown on line 0
Run Code Online (Sandbox Code Playgroud)
我跑了
php --ini
Run Code Online (Sandbox Code Playgroud)
而输出是
php --ini
PHP Warning: Module 'intl' already loaded in Unknown on line 0
Warning: Module 'intl' already loaded in Unknown on line 0
Configuration File (php.ini) Path: /usr/local/etc/php/5.5
Loaded Configuration File: /usr/local/etc/php/5.5/php.ini
Scan for additional .ini files in: /usr/local/etc/php/5.5/conf.d
Additional .ini files parsed: /usr/local/etc/php/5.5/conf.d/ext-apcu.ini,
/usr/local/etc/php/5.5/conf.d/ext-igbinary.ini,
/usr/local/etc/php/5.5/conf.d/ext-intl.ini,
/usr/local/etc/php/5.5/conf.d/ext-memcached.ini,
/usr/local/etc/php/5.5/conf.d/ext-mongo.ini,
/usr/local/etc/php/5.5/conf.d/ext-uuid.ini,
/usr/local/etc/php/5.5/conf.d/ext-xdebug.ini
Run Code Online (Sandbox Code Playgroud)
在php.ini文件中检查并且加载了intl的唯一位置在顶部并且它被注释掉了.其他文件内容如下所示:
extension="/usr/local/Cellar/php55/5.5.23/lib/php/extensions/no-debug-non-zts-20121212/intl.so"
Run Code Online (Sandbox Code Playgroud)
最后一个斜杠后面的内容是扩展名.
我不知道还能在哪里看.
任何帮助表示赞赏