我有一个String存储几个文件的处理结果.如何将该String写入项目中的.txt文件?我有另一个String变量,它是.txt文件的所需名称.
关于我之前的一个问题,我发布了:
我必须阅读几个非常大的txt文件,并且必须使用多个线程或单个线程来执行此操作,具体取决于用户输入.假设我有一个获取用户输入的main方法,并且用户请求单个线程并希望处理该线程的20个txt文件.我怎么做到这一点?请注意,下面不是我的代码或它的设置,而是"想法".
例:
int numFiles = 20;
int threads = 1;
String[] list = new String[20];
for(int i = 1; i < 21; i++){
list[i] = "hello" + i + ".txt";//so the list is a hello1.txt, hello2.txt, ..., hello20.txt
}
public void run(){
//processes txt file
}
Run Code Online (Sandbox Code Playgroud)
总而言之,如何通过单个线程实现这一目标?有20个线程?
并且用户建议使用threadPools:
当用户指定要使用的线程数时,您需要适当地配置池,提交一组文件读取作业,并让池对执行进行排序.在Java世界中,您将使用Executors.newFixedThreadPool工厂方法,并将每个作业提交为Callable.这是IBM关于Java线程池的一篇文章.
所以现在我有一个名为sortAndMap(String x)的方法,它接受一个txt文件名并进行处理,对于上面的例子,它会有
Executors.newFixedThreadPool(numThreads);
我如何在threadPools中使用它,以便我上面的例子可行?
我知道你可以通过输入创建一个按钮
JButton x= new JButton("Something");
x.addActionListener(this);
Run Code Online (Sandbox Code Playgroud)
但是我如何创建一个actionlistener,以便按钮为用户创建一个文本字段以提供输入....以及如何从该文本框中读取文本?
我有一些带有link_to
, say的文字"Hello 1 Hello 2 Hello 3"
。我需要该字符串成为如下所示的链接:
Hello 1
Hello 2
Hello 3
Run Code Online (Sandbox Code Playgroud)
我正在 Ruby/Haml 中工作,似乎无法完成此任务。知道怎么做吗?我尝试"\n"
在字符串中连接,但似乎也不起作用。
这是我的代码......
package calendar;
import java.util.*;
/**
* This class represents a simple implementation of a sorted singly-linked list.
* Elements added to the list are inserted in sorted order based on an specified
* Comparator object.
* <br><br>
*
* This class relies on two classes: MyIterator and MyListNode. We have implemented
* the MyListNode class for you, but you are responsible for the implementation
* of the MyIterator class. Notice these are inner classes defined within the
* MySortedLinkedList …
Run Code Online (Sandbox Code Playgroud)