在运行此代码时,我在线程“主要”中出现错误。 Java.Lang.Nullpointerexception在Test.Main(Test.Java:15)..我该怎么办? [英] While Running This Code I Got Error As Exception In Thread "Main" Java.Lang.Nullpointerexception At Test.Main(Test.Java:15)..Wta Should I Do?
本文介绍了在运行此代码时,我在线程“主要”中出现错误。 Java.Lang.Nullpointerexception在Test.Main(Test.Java:15)..我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import java.io.*;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
class Test {
public static void main(String[] args)throws IOException
{
BufferedReader input;
String line;
File intermediate = new File("myfile1.txt");
PrintWriter output = new PrintWriter(intermediate, "UTF-8");
String p = "hh";
File dir = new File(p);
File[] files = dir.listFiles();
for (File f : files)
{
if (f.isFile())
{
input = new BufferedReader(new FileReader(f));
line = String.format("[%s_DINAMALAR_DATE]", f.getName());
output.println(line);
System.out.println(line);
while ((line = input.readLine()) != null)
{
output.println(line);
System.out.println(line);
}
input.close();
}
}
output.close();
input = new BufferedReader(new FileReader(intermediate));
int count = 0;
output = null;
while ((line = input.readLine()) != null)
{
if (line.startsWith("["))
{
if (output != null) output.close();
output = new PrintWriter(new File(line + ".txt"), "UTF-8");
output.println(line);
count++;
continue;
}
output.println(line);
}
input.close();
}
}
推荐答案
确保路径
Be sure that the path
String p = "hh";
存在。我的意思是路径必须是真实完整的路径。希望这有帮助。
exists. I mean that the path must be a real and complete path. Hope this help.
这篇关于在运行此代码时,我在线程“主要”中出现错误。 Java.Lang.Nullpointerexception在Test.Main(Test.Java:15)..我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文