【发布时间】:2015-03-23 05:29:32
【问题描述】:
所以我目前正在从第一次开始从文本文件中读取信息,根据我拼凑的内容,以下代码应该可以工作并返回 100 和 16:
package Utility;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class textReader {
public textReader()
{}
public Object fetchElement(String fileName, String keyName)
{
Properties properties = new Properties();
try {
properties.load(new FileInputStream("P:/Real_Time_Survival/Real_Time_Survivial_Game/assets" + fileName));
} catch (IOException e) {
}
return properties.getProperty("keyName");
}
}
但是当从主类调用时
textReader ready = new textReader();
ready.fetchElement("Sprites/ExampleSprite/Default/SpriteData.txt", "FrameDuration");
ready.fetchElement("Sprites/ExampleSprite/Default/SpriteData.txt", "AnimationFrames");
它返回 null(让系统打印出这些行,由于格式错误而将其删除)。知道为什么这不起作用吗?
【问题讨论】:
-
打印 ioexception 的堆栈跟踪。读取文件时已经出现异常的可能性很高....
-
我在assets后面少了“/”,我傻了,但是如果有异常添加一行打印出来后,我可以看到没有。我要读取的文件如下: FrameDuration:100 AnimationFrames:16 这是格式不正确吗?
-
我在文件中使用了格式正确的信息示例,但它也返回 null。我有点难过,有什么想法吗?
标签: java text properties