js 怎么读写properties文件啊?

JavaScript022

js 怎么读写properties文件啊?,第1张

可以和读文本文件一样读取

fso = new ActiveXObject("Scripting.FileSystemObject")

f = fso.OpenTextFile("c:\fps.properties", ForWriting, true)

或者

用java代码把xx.properties拼成JSON放到那个页面的js代码块里

InputStream in = getProperties.class.getClassLoader().getResourceAsStream(

"config.properties")

这一句换个写法试试:

Properties props = new Properties()

String url = this.getClass().getClassLoader().getResource(

"config.properties").toString().substring(6)

String empUrl = url.replace("%20", " ")// 如果你的文件路径中包含空格,是必定会报错的

System.out.println(empUrl)

InputStream in = null

try {

in = new BufferedInputStream(new FileInputStream(empUrl))

props.load(in)

} catch (FileNotFoundException e1) {

e1.printStackTrace()

} catch (IOException e1) {

e1.printStackTrace()

}

我就是一直这么写的,没问题。

我猜你读取文件为空的原因,是你的文件路径有空格。