简体   繁体   English

在Java中将变量添加到文件路径

[英]Adding variables to file path in java

Is it possible to modify a file path so that it incorporates a String variable? 是否可以修改文件路径,使其包含String变量?

example code 示例代码

String var = "Picture.jpg";
   ImageIcon img = new ImageIcon("C:\\Users\\Main\\Documents\\CompSciProjects\\Memory Game\\var");

Use String.format 使用String.format

String var = "Picture.jpg";
ImageIcon img = new ImageIcon(String.format("C:\\Users\\Main\\Documents\\CompSciProjects\\Memory Game\\%s", var));

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

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