-2
import java.io.*;
class FileApi extends File
{
//Variables declaration
//declare object FileWriter and FileReader
FileWriter fw;
FileReader fr;
File file;
FileApi(String s)
{
super(s);
file = new File(s+".txt");
}
boolean fileExists()
{
if(file.exists())
return true;
else
return false;
}
/**
This method is used to create a new file in the
current directory
*/
void createFile() throws IOException
{
fw = new FileWriter(file);
fw.close();
}
/**
This method is used to write text into file
*/
void writeFile(String s)
{
try
{
fw = new FileWriter(file);
fw.write(s);
fw.close();
}catch(IOException asdf){
asdf.printStackTrace();
}
}
/**
This method is used to read text from file
*/
String readFile() throws Exception
{
fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String data;
while((data = br.readLine()) == null)
{
System.out.println(data);
}
fr.close();
return data;
}
}
スレッドに関する明確な理解はありません。このコードでスレッドを実装することは可能ですか?私はスレッドが2つのクラスのいずれかで実装できると思います。スレッドの全体的な概念は理解するのが非常に難しいです。さらに、コード全体を開発した後、スレッドを使用する機能は何ですか?このJavaコードにスレッドを実装する方法はありますか?
感謝。エラーは表示されません。しかし、値を検索すると結果が表示されません –