Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java.properties文件中没有';与键值模式不匹配_Java_Xml_Properties - Fatal编程技术网

Java.properties文件中没有';与键值模式不匹配

Java.properties文件中没有';与键值模式不匹配,java,xml,properties,Java,Xml,Properties,我有一个java库,我需要将其视为一个黑盒,它需要在类路径上存在一个属性文件。但是,我有一个系统,它只允许提供包含有效xml的配置文件 由于jar的黑盒特性,我无法使用loadFromXml()方法重新编译,也无法要求所有者这样做 为了解决这个明显的不匹配问题,我提供了一个如下所示的配置文件: <dummy> key1=value1 key2=value2 </dummy> 键1=值1 键2=值2 这可以很好地工作,并提供我想要访问的值 我找不到有关此格式错误的属性

我有一个java库,我需要将其视为一个黑盒,它需要在类路径上存在一个属性文件。但是,我有一个系统,它只允许提供包含有效xml的配置文件

由于jar的黑盒特性,我无法使用
loadFromXml()
方法重新编译,也无法要求所有者这样做

为了解决这个明显的不匹配问题,我提供了一个如下所示的配置文件:

<dummy>
key1=value1
key2=value2
</dummy>

键1=值1
键2=值2
这可以很好地工作,并提供我想要访问的值

我找不到有关此格式错误的属性文件的第一行和最后一行发生了什么的引用


有人知道会发生什么吗?他们有更好的解决方案吗?

您最终得到了键
的空字符串值。您可以很容易地显示这一点:

import java.io.*;
import java.util.*;
public class Test {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        try (InputStream input = new FileInputStream("test.properties")) {
            properties.load(input);
        }

        for (String key : properties.stringPropertyNames()) {
            System.out.println(key + " = '" + properties.get(key) + "'");
        }
    }
}
这至少在本部分中有所说明:

作为第三个示例,行:

cheeses
指定键为“cheeses”,关联元素为空字符串“”


。。。但是它并不像可能写得那么清楚。

您最终得到了键
的空字符串值。您可以很容易地显示这一点:

import java.io.*;
import java.util.*;
public class Test {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        try (InputStream input = new FileInputStream("test.properties")) {
            properties.load(input);
        }

        for (String key : properties.stringPropertyNames()) {
            System.out.println(key + " = '" + properties.get(key) + "'");
        }
    }
}
这至少在本部分中有所说明:

作为第三个示例,行:

cheeses
指定键为“cheeses”,关联元素为空字符串“”


。。。但是它并不像可能写得那么清楚。

您最终得到了键
的空字符串值。您可以很容易地显示这一点:

import java.io.*;
import java.util.*;
public class Test {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        try (InputStream input = new FileInputStream("test.properties")) {
            properties.load(input);
        }

        for (String key : properties.stringPropertyNames()) {
            System.out.println(key + " = '" + properties.get(key) + "'");
        }
    }
}
这至少在本部分中有所说明:

作为第三个示例,行:

cheeses
指定键为“cheeses”,关联元素为空字符串“”


。。。但是它并不像可能写得那么清楚。

您最终得到了键
的空字符串值。您可以很容易地显示这一点:

import java.io.*;
import java.util.*;
public class Test {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        try (InputStream input = new FileInputStream("test.properties")) {
            properties.load(input);
        }

        for (String key : properties.stringPropertyNames()) {
            System.out.println(key + " = '" + properties.get(key) + "'");
        }
    }
}
这至少在本部分中有所说明:

作为第三个示例,行:

cheeses
指定键为“cheeses”,关联元素为空字符串“”


。。。但是它写得不太清楚。

我不明白你的问题。xml文件有什么问题?配置文件看起来有点像INI文件格式。如果不包括该行,会发生什么?你的解决方案和任何方案一样好,只要它对你的过程有效。从本质上说,如果我离开这个项目,这类问题很容易被误解。我不理解你的问题。xml文件有什么问题?配置文件看起来有点像INI文件格式。如果不包括该行,会发生什么?你的解决方案和任何方案一样好,只要它对你的过程有效。从本质上说,如果我离开这个项目,这类问题很容易被误解。我不理解你的问题。xml文件有什么问题?配置文件看起来有点像INI文件格式。如果不包括该行,会发生什么?你的解决方案和任何方案一样好,只要它对你的过程有效。从本质上说,如果我离开这个项目,这类问题很容易被误解。我不理解你的问题。xml文件有什么问题?配置文件看起来有点像INI文件格式。如果不包括该行,会发生什么?你的解决方案和任何解决方案一样好,只要它对你的过程有效。从本质上说,如果我离开这个项目,这种解决方案很容易被误解。