英文:
Java Cannot be resolved as a type
问题
以下是您要翻译的部分:
Trying to follow tuto but seems not working for me. It's Maven tuto, you can go to 11min to see the original code:
[Tuto Link Maven ][1]
Please find below my code:
package org.example.demo;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.io.input.ClosedInputStream;
/**
* Hello world!
*
*/
public class App {
public static void main( String[] args ) throws IOException
{
System.out.println( "Hello World!" );
Properties vProp = new Properties();
InputStream vInputStream = null;
try {
vInputStream = App.class.getResourceAsStream("/info.properties");
vProp.load(vInputStream);
} finally {
if (vInputStream != null) {
vInputStream.close();
}
}
System.out.println("Application version :"+vProp.getProperty("org.example.demo.version+?"));
}
}
<details>
<summary>英文:</summary>
Trying to follow tuto but seems not working for me. It's Maven tuto, you can go to 11min to see the orignal code:
[Tuto Link Maven ][1]
Please find below my code:
package org.example.demo;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.io.input.ClosedInputStream;
/**
* Hello world!
*
*/
public class App {
public static void main( String[] args ) throws IOException
{
System.out.println( "Hello World!" );
Properties vProp = new Properties();
InputStream vInputStream = null;
try {
vInputStream = App.class.getResourceAsStream("/info.properties");
vProp load(vInputStream);
} finally {
if (vInputStream != null) {
vInputStream close();
}}
System.out.println("Application version :"+vProp.getProperty("org.example.demo.version+"+"?"));}
}
[![enter image description here][2]][2]
[![enter image description here][3]][3]
[1]: https://www.youtube.com/watch?v=EMiAFLQp8ow&list=PLxhnp_qsD8EOkX0_RagnbUITXircj-XLC&index=3
[2]: https://i.stack.imgur.com/OHJXl.png
[3]: https://i.stack.imgur.com/IowKL.jpg
</details>
# 答案1
**得分**: 1
`vProp.load(vInputStream)` 和 `vInputStream.close()`。
我还建议使用 try-with-resources 处理 vInputStream,无需调用 close 方法:
```java
try (InputStream vInputStream = App.class.getResourceAsStream("/info.properties")) {
vProp.load(vInputStream);
}
英文:
You have missing dots there...
vProp.load(vInputStream)
and vInputStream.close()
I would also suggest using try-with-resources for the vInputStream, no need for calling close then:
try (InputStream vInputStream = App.class.getResourceAsStream("/info.properties")) {
vProp.load(vInputStream);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论