我读过一篇关于机器学习的论文,它包含一个Oracle实验来比较他的研究和另一项研究?但似乎没有那么清楚什么是Oracle实验?
我需要从文件中读取两列(都是String),并将第一列的值保存在HashMap中,其中Integer是计数器.
例如,如果我正在阅读的文件是
Apple Fruit
PC Device
Pen Tool
...
Run Code Online (Sandbox Code Playgroud)
而代码是
String line="";
int counter=1;
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("test.txt"),"Unicode"));
while ((line = reader.readLine()) != null)
{
String[] words;
words= st.split(" ");
tokens.put(counter, words[0]);
counter+=1;
}
Run Code Online (Sandbox Code Playgroud)
问题是当我打印HashMap值时,我发现值与origianl文件中的值的顺序不同
for (Map.Entry<Integer, String> token:tokens.entrySet())
{
System.out.println(token.getKey() + token.getValue());
}
Run Code Online (Sandbox Code Playgroud)
我得到了以下内容
1 Apple
3 Pen
4 whatever
2 ..etc
Run Code Online (Sandbox Code Playgroud)
我不知道是什么问题?!你可以帮助我吗?
我在下面的路径中有一个perl脚本(/home/Leen/Desktop/Tools/bin/tool.pl)每次我想运行这个工具我都会去终端
>
Run Code Online (Sandbox Code Playgroud)
然后将目录更改为
... /斌>
然后我通过写作运行perl
..../bin> perl tool.pl file= whatever config= whatever
Run Code Online (Sandbox Code Playgroud)
问题是我想运行这个perl脚本而不需要转到它所在的bin文件夹.所以我可以从任何目录运行perl脚本,一旦我输入shell,我就去了etc/environment我写了下面的内容
export PERL5LIB = $ PERL5LIB:/ home/Leen/Desktop/Tools/bin
但是当我去终端并直接写下面而没有进入tool文件夹存在的bin文件夹时
>perl tool.pl file=... config=...
Run Code Online (Sandbox Code Playgroud)
它说文件"tool.pl"不存在???
我有一个perl脚本需要运行2个参数.我目前正在使用Ubuntu,我设法通过将目录更改为perl脚本所在的位置并通过写入来执行来自终端的perl脚本
perl tool.pl config=../mydefault.config file=../Test
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试从我的java程序运行perl脚本时(我正在使用eclipse),它总是给我消息Command Failure.这是代码:
Process process;
try {
process = Runtime.getRuntime().exec("perl /home/Leen/Desktop/Tools/bin/tool.pl config=../mydefault.config file=../Test");
process.waitFor();
if(process.exitValue() == 0) {
System.out.println("Command Successful");
} else {
System.out.println("Command Failure");
}
} catch(Exception e) {
System.out.println("Exception: "+ e.toString());
}
Run Code Online (Sandbox Code Playgroud)
那么请问我的代码有什么问题?
我有一个java程序,它读取文件文本中的每一行并处理文件的文本,然后打印结果.我需要对特定文件夹(目录)中存在的每个文件执行相同的操作.所以,我需要程序遍历文件夹中的每个文件并提取文本内容..etc.我的问题是如何使用Java循环遍历文件夹中的每个文件.