你好我对java和编程相当陌生。我想知道如何读取文本文件(test.txt)并实现它以执行一个过程,例如在链表中创建和删除节点以及为它们分配一个值。例如,如果 txt 文件读取:
插入 1
插入 3
删除 3
我希望程序创建一个节点并为其分配值 1,创建一个节点并为其分配值 3,然后删除具有分配值 3 的那个节点。
这是我到目前为止的一些粗略代码。谢谢你。
代码:
import java.io.*;
class FileRead
{
public static void main(String args[])
{
try
{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}