使用Properties类带来的好处

SAP交货单增强字段更新实战:手把手教你用BAPI_OUTB_DELIVERY_CHANGE和EXTENSION2参数 本文详细解析了如何使用BAPI_OUTB_DELIVERY_CHANGE和EXTENSION2参数实现SAP交货单增强字段的更新。从增强点SMOD_V50B0001的定位到字段落表的全流程,提供了ABAP代码示例和常见问题排查方法,帮助开发者高效完成交货单自定义字段的集成开发。 阅读详情
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> Monday, February 24 2003 3:18 PM 许多开发者抱怨C++不能像Java那样绑定Properties类。Java的Properties类内在包含一个文件,该文件用来读写Properties类中的属性,可以写成这样形式:<名字>=<数值>(例如:ConnectToInternet=Use IE)。 使用Properties类的好处就是你可以很轻松的理解和修改它们。在本文的第一部分中,你将看到我们也可以在C++中使用Properties类。本文的第二部分将向你演示通过使用操作符>>和<<把数据保存到Properties类中是多么的容易。 现在介绍C++ Properties文件的结构。该文件的每一行可以是下面三种情况中的某一种: 空行(认为它是注释中的一部分) 以‘#’ 开始的注释行 ‘<名字>=<数值>’行,这是给一个属性赋值的语句 现在让我们再看看Properties类的的特点: 注释是持久性的(当保存Properties类时,它们不会丢失掉)。注意每一个注释都属于某个属性。在‘<名字>=<数值>’行上的注释行属于该‘<名字>’属性。 当保存Properties类后,属性仍然保留自己的位置。 它对各种字符类型都有效:char、wchar_t等等 Properties类的使用相当简单: save():保存属性 has_property(strPropertyName):如果类中有该属性则返回‘真’ string get_property(strPropertyName):返回指定的属性(如果指定属性不存在,则抛出例外) set_property(strPropertyName, strPropertyValue):设置给定属性 stringget_property_comment( strPropertyName):返回属于指定属性的注释(如果指定属性的注释不存在,则抛出例外) set_property_comment(strPropertyName, strPropertyComment):设置指定属性的注释(如果指定属性的注释不存在,则抛出例外) 下面是file_reader_writer类以及相应例子的代码。运行它之后,请查看properties.txt文件。看看访问和修改它是多么容易的一件事。 #include exception> #include string> #include sstream> #include map> #include vector> #include fstream> #include algorithm> #include functional> //允许字符串转化 template< class FromCharType, class ToCharType> inline std::basic_string< ToCharType> convert_string( const std::basic_string< FromCharType> & strSource) { std::basic_string< ToCharType> strDest; int nSourceLen = strSource.length(); strDest.resize( nSourceLen); for ( int idxChar = 0; idxChar < nSourceLen; idxChar ) { strDest[ idxChar] = ( ToCharType)strSource[ idxChar]; } return strDest; } // 用于trim_spaces; template< class CharType> struct is_char_in_str : public std::binary_function< CharType, std::basic_string< CharType>, bool> { bool operator()( CharType ch, const std::basic_string< CharType> & strSource) const { return (strSource.find( ch) != std::basic_string< CharType>::npos); } }; //消除字符串中的空格 template< class CharType> std::basic_string< CharType> trim_spaces( const std::basic_string< CharType> & strSource) { std::basic_string< CharType> strSpaces; strSpaces = ( CharType)' '; strSpaces = ( CharType)'/t'; typedef std::basic_string< CharType> string_type; string_type::const_iterator itFirst = std::find_if( strSource.begin(), strSource.end(), std::not1( std::bind2nd( is_char_in_str< CharType>(), strSpaces))); string_type::const_reverse_iterator ritLast = std::find_if( strSource.rbegin(), strSource.rend(), std::not1( std::bind2nd( is_char_in_str< CharType>(), strSpaces))); string_type::const_iterator itLast = &*ritLast; if ( itFirst <= itLast) if ( itFirst != strSource.end()) return string_type( itFirst, itLast 1); return string_type(); } // 当读写属性时的例外 class properties_exception : public std::exception { public: properties_exception( const std::string & str) : m_strDescription( str) {} const char * what() const { return m_strDescription.c_str(); } private: std::string m_strDescription; }; // 从文件中读写属性 template< class CharType> class file_reader_writer { typedef std::basic_string< CharType> string_type; public: // ... needed within the basic_properties! typedef CharType char_type; public: file_reader_writer( const char * strFileName) : m_bIsDirty( false), m_strFileName( strFileName) { read_properties(); } ~file_reader_writer() { save(); } void save() { write_properties(); } bool has_property( const string_type & strPropertyName) const { PropertiesCollection::const_iterator itFound = m_collProperties.find( strPropertyName); return ( itFound != m_collProperties.end()); } const string_type & get_property( const string_type & strPropertyName) const { PropertiesCollection::const_iterator itFound = m_collProperties.find( strPropertyName); if ( itFound != m_collProperties.end()) return itFound->second.m_strValue; else throw properties_exception( "Cound not get property value for '" convert_string< char_type, char>( strPropertyName) "', since this property does not exist."); } void set_property( const string_type & strProperty, const string_type & strPropertyValue) { PropertiesCollection::iterator itFound = m_collProperties.find( strProperty); if ( itFound == m_collProperties.end()) // 它是一个新的属性 m_aProperties.push_back( strProperty); m_collProperties[ strProperty].m_strValue = strPropertyValue; m_bIsDirty = true; } const string_type & get_property_comment( const string_type & strPropertyName) const { PropertiesCollection::const_iterator itFound = m_collProperties.find( strPropertyName); if ( itFound != m_collProperties.end()) return itFound->second.m_strComment; else throw properties_exception( "Cound not get property comment for '" convert_string< char_type, char>( strPropertyName) "', since this property does not exist."); } void set_property_comment( const string_type & strPropertyName, const string_type & strPropertyComment) { PropertiesCollection::iterator itFound = m_collProperties.find( strPropertyName); if ( itFound != m_collProperties.end()) itFound->second.m_strComment = strPropertyComment; else throw properties_exception( "Cound not set property comment for '" convert_string< char_type, char>( strPropertyName) "', since this property does not exist."); m_bIsDirty = true; } private: static const char_type get_delimeter() { return '='; } static const char_type get_comment() { return '#'; } void read_properties() { const char DELIMETER = get_delimeter(); const char COMMENT = get_comment(); std::basic_ifstream< char_type> streamIn( m_strFileName.c_str()); string_type strLine; string_type strComment; while ( std::getline( streamIn, strLine)) { strLine = trim_spaces( strLine); bool bIsComment = strLine.empty() || ( strLine[ 0] == COMMENT); if ( bIsComment) { strComment = strLine; strComment = '/n'; } else { int idxDelimeter = strLine.find( DELIMETER); if ( idxDelimeter != string_type::npos) { string_type strPropertyName = strLine.substr( 0, idxDelimeter); string_type strPropertyValue = strLine.substr( idxDelimeter 1); strPropertyName = trim_spaces( strPropertyName); strPropertyValue = trim_spaces( strPropertyValue); m_collProperties.insert( std::make_pair( strPropertyName, OneProperty( strPropertyValue, strComment))); m_aProperties.push_back( strPropertyName); strComment.erase(); } else throw properties_exception( "While reading from file '" m_strFileName "', we encountered an invalid line: /n" convert_string< char_type, char>( strLine)); } } m_strLastComment = strComment; } void write_properties() const { if ( !m_bIsDirty) // 无需保存 ;return; const char DELIMETER = get_delimeter(); std::basic_ofstream< char_type> streamOut( m_strFileName.c_str()); PropertiesArray::const_iterator itFirst = m_aProperties.begin(), itLast = m_aProperties.end(); while ( itFirst != itLast) { const string_type & strPropertyName = *itFirst; const OneProperty & property = m_collProperties.find( strPropertyName)->second; write_property_comment( streamOut, property.m_strComment); string_type strToWrite = strPropertyName; strToWrite = ' '; strToWrite = DELIMETER; strToWrite = ' '; streamOut strToWrite << property.m_strValue << std::endl; itFirst; } write_property_comment( streamOut, m_strLastComment); m_bIsDirty = false; } void write_property_comment( std::basic_ofstream< char_type> & streamOut, const string_type & strComment) const { const char COMMENT = get_comment(); std::basic_stringstream< char_type> streamComment( strComment); string_type strLine; while ( std::getline( streamComment, strLine)) { if ( !strLine.empty()) if ( strLine[ 0] == COMMENT) streamOut << strLine << std::endl; else { string_type strPrefix; strPrefix = COMMENT; strPrefix = ' '; streamOut << strPrefix << strLine << std::endl; } else streamOut << std::endl; } } private: // 我们用来读写的文件 std::string m_strFileName; //如果自上次保存后属性又有修改则赋值为“真” mutable bool m_bIsDirty; struct OneProperty { OneProperty() {} OneProperty( const string_type & strValue, const string_type & strComment) : m_strValue( strValue), m_strComment( strComment) {} string_type m_strValue; string_type m_strComment; }; // 属性 typedef std::map< string_type, OneProperty> PropertiesCollection; PropertiesCollection m_collProperties; // ……确保我们是按同样的次序保存属性 // 读属性 typedef std::vector< string_type> PropertiesArray; PropertiesArray m_aProperties; // 读取所有属性后的注释 string_type m_strLastComment; }; 下面是用到这个类的一个例子: #include int main(int argc, char* argv[]) { file_reader_writer< char> rw( "properties.txt"); rw.set_property( "App Path", "C:/Program Files/PFS/jokExplorer"); rw.set_property_comment( "App Path", "where are we installed?"); rw.set_property( "Version", "4.0.0.1"); rw.set_property_comment( "Version", "What's our version?"); rw.set_property( "Run On Startup", "1"); rw.set_property_comment( "Run On Startup", "are we run, when the computer starts?"); rw.set_property( "Automatic Logoff Minutes", "60"); rw.set_property_comment( "Automatic Logoff Minutes", "when should we deconnect from the server?"); rw.set_property( "Connect To Internet", "Use IE"); rw.set_property_comment( "Connect To Internet", "how are we to connect to the Internet?"); std::cout << "This is how we connect to Internet: " << rw.get_property( "Connect To Internet") << std::endl; return 0; }
【FPGA教程案例59】深度学习案例6——基于FPGA的CNN卷积神经网络之整体实现 在课程,我们对的基本原理有了初步认识。在上一个课程,我们完成了CNN的Relu激活层、pool池化层、卷积层以及图像输入层的实现,如下图所示:在本课程中,我们将上述四个模块结合起来,构建一个简单的CNN卷积神经网络。... 阅读详情

相关推荐

ADS高级技巧:用DAC控件实现多变量参数扫描(以S参数和阻抗匹配为例)

本文深入解析了ADS软件中DAC控件的高级应用,指导用户如何利用其实现多变量参数扫描。通过构建支持多变量的MDF文件,并将其与原理图变量动态映射,可以高效完成如S参数和阻抗匹配等复杂场景的联合仿真与可视化分析,显著提升射频电路设计的效率和深度。

3a9bq4r8t2y的博客 260

java编程中Properties类的具体作用和使用

如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的。(如清单 1 所示)。最近更新的java.util.Properties 类现在提供了一种为程序装载和存储设置的更容易的方法: loadFromXML(InputStreamis) 和 storeToXML(OutputStream os, String co

Golden_lion的博客 8001

【机器人】线性方程最小二乘解法对机械臂DH参数进行标定

1.前言 看了一篇文章,觉得里面的DH参数标定法讲的很清晰,便使用Matlab复现了一下,效果还可以,特写此文记录。 2.原理 2.1.误差最佳值的最小二乘计算 有研究结果表明:几乎95%的机器人位置误差都是由机器人内部运动学的不准确描述引起的,所以对DH模型参数进行标定是很有必要的。 DH参数物理含义:选自《机器人学、机器视觉与控制-Matlab基础》 当DH参数确定后,我们...

要恰饭得嘛 1万+

java中properties作用,Java中Properties集合

Properties 类表示了一个持久化的属性集,可保存在流中或从流中加载,属性列表中每个键及其对应的值都是一个字符串1、Properties 集合特点Properties 类是 Hashtable 的子类,Map 集合中的方法都可以用该集合没有泛型,键值都是字符串是一个可以持久化的属性集,键值可以存储到集合中,也可以存储到持久化的设备(硬盘、U盘、光盘)上,键值的来源也可以是持久化的设备有和流技...

weixin_28674303的博客 421

Qt C++:跨平台开发利器

摘要: Qt C++是基于C++的跨平台开发框架,通过元对象系统、信号槽机制及模块化架构实现"一次编写,多端部署"。核心特性包括: 跨平台能力:覆盖桌面(Windows/macOS/Linux)、移动端(iOS/Android)、嵌入式及WebAssembly; 信号与槽:替代传统回调,实现对象间高效通信; UI组件库:200+预制组件支持QSS样式定制; 工具链:Qt Creator集成开发环境提供可视化设计、调试及多平台编译。 广泛应用于工业控制、车载系统、医疗设备及跨平台应用开发,

2202_75382767的博客 1691

微光图像增强算法实战解析:从理论到实现

本文深入解析了微光图像增强算法的核心原理与实战应用。从经典的Retinex理论和LIME算法入手,剖析了基于光照估计的传统优化方法;进而探讨了深度学习时代无参考学习与引入正常光先验的网络模型。文章还提供了完整的Python实战代码,手把手教你实现一个简易的微光增强管道,涵盖从理论到落地的关键步骤。

weixin_29032337的博客 246

MATLAB 面向对象编程——类,属性,方法

handle是 MATLAB 的抽象类,做父类classdef 类名 < 继承类properties %属性 %... end methods %方法 %... end endproperties %属性xy%...endmethods %方法obj.x = x0;obj.y = y0;endendendend表示二维坐标轴上的点,具有x,y坐标属性作为其属性methods 定义了两个方法,一个是(Constructor) 构造方法;一个是其他的使用函数。

青年有志 6628

MIPI转LVDS芯片调试实战:从Kernel到UEFI的完整点亮流程

本文详细解析了MIPI转LVDS芯片调试的全流程,从Kernel驱动开发到UEFI早期初始化,涵盖I2C通信、电源时序控制等核心挑战。通过LT9211芯片实战案例,提供设备树配置、电源时序优化及显示异常排查等实用技巧,助力工程师高效完成屏幕调试工作。

weixin_30314813的博客 454

Matlab中的类组件

目录 类组件 类构建块 类定义代码块 属性代码块 方法代码块 事件代码块 完整类 枚举类 类组件 类构建块 MATLAB®将类定义代码组织成模块化代码块,以关键字分隔。所有关键字都有相关联的end语句: classdef...end- 所有类组件的定义 properties...end- 属性名称声明、属性特性设定、默认值赋值 methods...end- 方法签名、方法属性和函数代码的声明 events...end- 事件名称和属...

jk_101的博客 755

同态加密与SEAL库实战:CKKS参数调优避坑指南

本文深入探讨了同态加密技术中CKKS方案的参数调优实践,重点解析了SEAL库中`poly_modulus_degree`、`coeff_modulus`和`scale`三大核心参数的配置技巧与避坑指南。通过实战案例展示了如何平衡计算深度、精度与性能,为开发者提供了一套完整的参数优化方法论,帮助避免常见的'scale out of bounds'等错误,显著提升同态加密应用的可靠性和效率。

weixin_29315569的博客 234

Vulkan入门系列3 - 绘制三角形代码解析(全)

【代码】Vulkan入门系列3 - 绘制三角形完整代码(带详细注释)

GPU全栈博主 1041

关于properties的简单介绍

properties是一种配置文件,文件里面内容以“键=值”的方式写入,相当于集合里面的Map,拿值时以键取值即可。用途较广,例如可用在数据库连接类,存储数据库名与密码,优点是需改动数据库名或密码时不需改源码,改动properties文件即可,方便维护。以下为properties文件示例: 以下为properties内容读取部分的代码:

qq_38446250的博客 2959

一文学会Inner-MPDIoU:YOLOv11边界框回归优化全解析

Inner-MPDIoU 凭借“辅助边框+最小点距离”的双重创新,成功解决了传统 IoU 损失在小目标、遮挡场景、位置偏差场景下的收敛和判别难题,为 YOLOv11 注入了更强的边框回归能力。从原理剖析到代码集成,本教程已为你铺就了一条“定位精度跃升”的实战路径。现在,不妨亲自上手尝试,让你的目标检测模型在各类数据集上都能交出一份“定位精准”的答卷——相信我,当你看到检测框完美贴合目标的那一刻,你会明白这份尝试的价值。我很乐意在你实践过程中帮你解决任何问题,让我们一起推动目标检测在边框回归领域的边界。

know_F0727的博客 151

JAVA基础:使用Properties类带来的好处(转)

JAVA基础:使用Properties类带来的好处(转)[@more@]许多开发者抱怨C++不能像Java那样绑定Properties类。Java的Properties类内在包含一个文件,该文件用来读写Properties类中的...

308

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Java-Properties类和properties文件详解

Java开发中配置文件是存储程序参数的常用方式,而properties文件因其简洁的键值对格式,成为最常用的配置文件类型之一,与之配套的java.util.Properties类,则是操作properties文件的核心工具。本文我将详细讲解properties配置文件的格式规范、Properties类的常用方法,以及在实际开发中的读写操作和最佳实践。

aa_hdkf_vg的博客 1783

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Properties类的使用

转载:https://www.cnblogs.com/bakari/p/3562244.html 一、Java Properties类 Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件,各种语言都有自己所支持的配置文件,配置文件中很多变量是经常改变的,这样做也是为了方便用户,让用户能够脱离程序本身去修改相关的变量...

博客 357

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

Properties类给你带来一点小帮助

Properties 类表示了一个持久的属性集。Properties 可保存在流中或从流中加载。属性列表中每个键及其对应值都是一个字符串。 一个属性列表可包含另一个属性列表作为它的“默认值”;如果未能在原有的属性列表中搜索到属性键,则搜索第二个属性列表。

ricky73999的博客 505

java.util.Properties类操作properties文件

文章目录1 Properties类1.1 认识properties文件1.2 了解Properties类1.3 properties文件与Properties类的关系1.4 使用Properties类1.4.1 操作properties1.4.2 操作XML文件1.4.3 java读取properties文件的九种方法 1 Properties类 由于java.util.Properties类也是属于继承Map的,所以就归类到集合这章了 1.1 认识properties文件 了解并认识properties文

上善若泪 3136

Java中Properties类使用

一、Properties简介: Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的 配置文件,各种语言都有自己所支持的配置文件,配置文件中很多变量是经常改变的,这样 做也是为了方便用户,让用户能够脱离程序本身去修改相关的变量设置。像Python支持的配 置文件是.ini文件,同样,它也有自己读取配置文件的类Conf...

zw1_csdn的博客 1780

Properties类的使用方法

java.util.Properties类  用于读取.properties文本文件的类 properties文件是一个纯文本文件,里面定义的内容格式有要求, 必须是key=value的形式,并且以行为单位, 一行只记录一条数据,下图是一个properties的书写案例 Properties类可以方便的读取properties文件,并将内容  以类似HashMap的形式进行读取。注

低头低啊低的博客 869

java.util.properties 类的使用

Properties 基本知识 如果不熟悉 java.util.Properties 类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的,如清单 1 所示。 清单 1. 一组属性示例 foo=bar fu=baz 将清单 1 装载到 Properties 对象中后,您就可以找到两个键( foo 和 fu )和两个值( foo 的 bar 和

Cece_2012的专栏 1万+

java properties 类_Java中Properties 类的详细使用

我把你的头像,设置成我的名字,此刻你便与我同在。我把你的名字,写进我的代码里面,以后,我的世界便存在着你。一.Properties 类Properties 类位于 java.util.Properties ,是Java 语言的配置文件所使用的类, Xxx.properties 为Java 语言常见的配置文件,如数据库的配置 jdbc.properties, 系统参数配置 system.proper...

weixin_35735398的博客 466

Java Properties类使用详解

概述 Properties 继承于 Hashtable。表示一个持久的属性集,属性列表以key-value的形式存在,key和value都是字符串。 Properties 类被许多Java类使用。例如,在获取环境变量时它就作为System.getProperties()方法的返回值。 我们在很多需要避免硬编码的应用场景下需要使用properties文件来加载程序需要的配置信息,比如JDBC、M...

_夜渐凉 1200

Properties 类的使用

Properties 类已不是新东西了,它在 Java 编程的早期就有了,并且几乎没有什么变化。J2SE 的 Tiger 版本增强了这个类,不仅可以用它在单独一行中指定用等号分隔的多个键-值对,还可以用XML 文件装载和保存这些键-值对。在 驯服 Tiger的这一期文章中,John Zukowski 展示了如何驾驭这匹新一代的“役马”。请在本文对应的讨论论坛上与作者及其他读者分享您对本文的想法(您

dainiao01的专栏 849
上一篇: Sun CEO麦克尼利:我给你选择的自由
下一篇: 操纵java数组
java169
博客等级 码龄19年 27粉丝 2568原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址