java配置文件读写(java配置文件格式)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

本篇文章给大家谈谈java配置文件读写,以及java配置文件格式对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

Java文件读写

实用的模糊(通配符)文件查找程序

1 import java.io.File;

2 import java.util.regex.Matcher;

3 import java.util.regex.Pattern;

4 import java.util.ArrayList;

5

6 /** *//**

7 * pTitle: FileService /p

8* pDescription: 获取文件 /p

9* pCopyright: Copyright (c) 2007/p

10* pCompany: /p

11* @author not attributable

12* @version 1.0

13*/

14public class FileService {

15 public FileService() {

16 }

17

18 /** *//**

19 * 在本文件夹下查找

20 * @param s String 文件名

21 * @return File[] 找到的悄汪圆文件

22 */

23 public static File[] getFiles(String s)

24 {

25 return getFiles("./",s);

26 }

27

28 /** *//**

29 * 获取文件

30 * 可以根据正则表达式查找启塌

31 * @param dir String 文件夹名称

32 * @param s String 查找文件名,可带*.?进行模糊查询

33 * @return File[] 找到的文件

34 */

35 public static File[] getFiles(String dir,String s) {

36 //开始的文件夹

37 File file = new File(dir);

38

39 s = s.replace('.', '#');

40 s = s.replaceAll("#", "\\\\.");

41 s = s.replace('*', '#');

42 s = s.replaceAll("#", ".*");

43 s = s.replace('?', '#');

44 s = s.replaceAll("#", ".?");

45 s = "^" + s + "$";

46

47 System.out.println(s);

48 Pattern p = Pattern.compile(s);

49 ArrayList list = filePattern(file, p);

50

51 File[] rtn = new File[list.size()];

52 list.toArray(rtn);

53 return rtn;

54 }

55

56 /** *//**

57 * @param file File 起始文件夹

58 * @param p Pattern 匹配类型

59 * @return ArrayList 其文件夹下的文件陵茄夹

60 */

61

62 private static ArrayList filePattern(File file, Pattern p) {

63 if (file == null) {

64 return null;

65 }

66 else if (file.isFile()) {

67 Matcher fMatcher = p.matcher(file.getName());

68 if (fMatcher.matches()) {

69 ArrayList list = new ArrayList();

70 list.add(file);

71 return list;

72 }

73 }

74 else if (file.isDirectory()) {

75 File[] files = file.listFiles();

76 if (files != null files.length 0) {

77 ArrayList list = new ArrayList();

78 for (int i = 0; i files.length; i++) {

79 ArrayList rlist = filePattern(files[i], p);

80 if (rlist != null) {

81 list.addAll(rlist);

82 }

83 }

84 return list;

85 }

86 }

87 return null;

88 }

89

90 /** *//**

91 * 测试

92 * @param args String[]

93 */

94 public static void main(String[] args) {

95 }

96}

JAVA中值的读写,在变量、常量、配置文件和数据库表的取舍?

程序中的不可变量,非集合形态的可以写成静态常量 集合形态的可以写成enum类

程序初始化参数,本地可更改变量,数据较少可以存放于properties文件,大量数据可以选择XML,便于解析与更改

大型橘笑的数据集合应存放与数据库中,数据库可圆局含以良好的管理大型数据集合,并且加快索引速度

单机程序一般都选择XML为存储源,或者自定义存储格式

网络程序腊颤才用到数据库

java读取配置文件的方法(xml)

#include XMLDoc.hpp

——相关说明

_di_IXMLDocument 为模板类

typedef System::DelphiInterface IXMLDocument _di_IXMLDocument;

_di_IXMLNode

typedef System::DelphiInterface IXMLNode _di_IXMLNode;

_di_IXMLNodeList 同

——类方法

//设置参数

void TXXX::setOptions(String name,String value){

//创建文档对象

_di_IXMLDocument XMLDoc = LoadXMLDocument(L"文件路径");

XMLDoc-Active=true;

//文档根节点野哗

_di_IXMLNode root = XMLDoc-DocumentElement;

/岁洞/想要查找节点

_di_IXMLNode tempNode;

//调用搜索方法

searchXml(name,root,tempNode);

// 处理

if(tempNode!=NULL)

tempNode-SetText(value);

XMLDoc-SaveToFile(L"文件路径");

}

//递归搜索参数节点树

void TXXX::searchXml(String name,_di_IXMLNode Parent_Node,_di_IXMLNode tempNode){

_di_IXMLNode Child_Node; //子结点

//子乎脊枯节点列表

_di_IXMLNodeList list = Parent_Node-ChildNodes;

for(int i=0;ilist-Count;i++)

{

Child_Node = list-Get(i);

//递归结束条件

if(Child_Node-GetNodeName()==name)

{

tempNode = Child_Node;

break;

}

else

{

//递归函数

searchXml(name,Child_Node,tempNode);

}

}

}

在JAVA如何采用LIST读写properties文件中的值

是败散不是要返嫌这个啊

Properties prop = new Properties();

prop.load(new FileInputStream(new File("察世氏path")));

List list = new ArrayList(prop.entrySet());

Java读取文件的几种方法

方式一:采用ServletContext读取,读取配置文件的realpath,然后通过文件流读取出来。因为是用ServletContext读取文件路径,所以配置文件可以放入在web-info的classes目录中,也可以在应用层级及web-info的目录中。文件存放位置具体在eclipse工程中的表现是:可以放在src下面,也可放在web-info及webroot下面等。因为是读取出路径猛掘后,用文件流进行读取的,所以可以读取任意的配置文件包括xml和properties。缺点:不能在servlet外冲毕面应用读取配置信息。

方式二:采用ResourceBundle类读取配置信息,

优点是:可以以完全散知芹限定类名的方式加载资源后,直接的读取出来,且可以在非Web应用中读取资源文件。缺点:只能加载类classes下面的资源文件且只能读取.properties文件。

方式三:采用ClassLoader方式进行读取配置信息

优点是:可以在非Web应用中读取配置资源信息,可以读取任意的资源文件信息

缺点:只能加载类classes下面的资源文件。

方法4 getResouceAsStream

XmlParserHandler.class.getResourceAsStream 与classloader不同

求用java读写properties文件的代码

Java代码

package com.LY;

import java.io.BufferedInputStream;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Enumeration;

import java.util.Properties;

public class TestMain {

// 根据key读取value

public static String readValue(String filePath, String key) {

Properties props = new Properties();

try {

InputStream in = new BufferedInputStream(new FileInputStream(

filePath));

props.load(in);

String value = props.getProperty(key);

System.out.println(key + value);

return value;

} catch (Exception e) {

e.printStackTrace();

return null;

}

}

// 读取properties的全部信息

public static void readProperties(String filePath) {

Properties props = new Properties();

try {

InputStream in = new BufferedInputStream(new FileInputStream(

filePath));

props.load(in);

Enumeration en = props.propertyNames();

while (en.hasMoreElements()) {

String key = (String) en.nextElement();

String Property = props.getProperty(key);

System.out.println(key + Property);

}

} catch (Exception e) {

e.printStackTrace();

}

}

// 写入properties信息

public static void writeProperties(String filePath, String parameterName,

String parameterValue) {

Properties prop = new Properties();

try {

InputStream fis = new FileInputStream(filePath);

// 从输入流中读取属性列表(键和扰滚帆元素对缓雹)

prop.load(fis);

// 调用 Hashtable 的方法 put。使用 getProperty 方法提供并行性。

// 强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。

OutputStream fos = new FileOutputStream(filePath);

prop.setProperty(parameterName, parameterValue);

// 以适合使用 load 方法加载到 Properties表中的格式,

// 将此 Properties 表中的属性列表(键和元素对)写入输出流

prop.store(fos, "Update '" + parameterName+ "备郑' value");

} catch (IOException e) {

System.err.println("Visit " + filePath + " for updating "

+ parameterName + " value error");

}

}

public static void main(String[] args) {

readValue("info.properties", "url");

writeProperties("info.properties", "age","22");

readProperties("info.properties");

System.out.println("OK");

}

}

关于java配置文件读写和java配置文件格式的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

发布于 2023-04-14 16:04:04
收藏
分享
海报
30
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了