java实现文件保存可以使用相对地址吗,怎么写相对地址?

java实现文件保存可以使用相对地址吗,怎么写相对地址?,第1张

绝对路径是从盘符开始的路径,形如

C:\windows\system32\cmd.exe

相对路径:是从当前路径开始的路径,假如当前路径为C:\windows

要描述上述路径,只需输入

system32\cmd.exe

实际上,严格的相对路径写法应为

.\system32\cmd.exe

其中,.表示当前路径,在通道情况下可以省略,只有在特殊的情况下不能省略。

假如当前路径为c:\program files

要调用上述命令,则需要输入

..\windows\system32\cmd.exe

其中,..为父目录。

当前路径如果为c:\program files\common files

则需要输入

..\..\windows\system32\cmd.exe

test

|

src

|

t090417

|

test.properties

Read.java

test.properties:

TEST=test

Read.java:

import java.io.FileInputStream

import java.io.FileNotFoundException

import java.io.IOException

import java.util.Properties

public class Read {

public static String TEST

private static Properties loadPropertyFile() throws FileNotFoundException,IOException{

Properties properties = new Properties()

FileInputStream fs = new FileInputStream("src/t090417/test.properties")

properties.load(fs)

return properties

}

public static void loadProperty(){

try{

Properties properties = loadPropertyFile()

TEST = properties.getProperty("TEST")

System.out.println("read from properties: "+TEST)

}catch(Exception e){

e.printStackTrace()

}

}

public static void main(String[] args) {

loadProperty()

}

}

其中用的就是相对路径!


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/11664673.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-17
下一篇2023-05-17

发表评论

登录后才能评论

评论列表(0条)

    保存