我写了一段代码来从文件中读取值,
public class Test
{
public static void main(String[] args) throws Exception
{
// pass the path to the file as a parameter
FileReader fr =
new FileReader("/home/workspace_ag7_tmv/Message Router/environments/wb/conf/subscriber_content_restriction.conf");
int i;
while ((i=fr.read()) != -1)
System.out.print((char) i);
}
}
在我的文件中,我传递了这些值:PRE | 00000000110000200000049UPOS | 10000000110000200000049U
我能够使用上面的代码来获取这些值,现在我想获取第四个索引值。您能帮我怎么做吗?
您可以将字符添加到ArrayList,然后在第4个索引处获取元素。
int i;
List<Character> charList = new ArrayList<>();
while ((i=fr.read()) != -1)
charList.add(char);
System.out.print((char) i);
}
char a = charList.get(4);