简体   繁体   English

使用Java的Windows机器中的绝对文件路径是什么?

[英]what is absolute file path in windows machine using java?

I am refering file path in two places in my program. 我在程序的两个位置引用文件路径。 In one place, i pass file path in FileInputStream and in another place i pass to Spring getResource() method. 在一个地方,我在FileInputStream中传递文件路径,在另一个地方,我传递给Spring getResource()方法。

If i give file path in FileInputStream like " file:/C:/myfile " it is throwing error. 如果我在FileInputStream中提供文件路径,例如“ file:/C:/myfile ”,则会抛出错误。 I had to give C:\\\\myfile . 我必须给C:\\\\myfile

But in getResource() method, if i give C:\\\\myfile it is throwing error i had to give file:/C:/myfile . 但是在getResource()方法中,如果我给出C:\\\\myfile ,则会抛出错误,我必须给出file:/C:/myfile

Why this difference? 为什么会有这种差异? Can you please clarify? 你能澄清一下吗?

FileInputStream is taking a String representing file path. FileInputStream采用表示文件路径的String getResource() from Spring is taking URL string representation of the resource. Spring的getResource()正在使用资源的URL字符串表示形式。

Those two are not the same. 那两个不一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM