【发布时间】:2015-04-21 05:34:52
【问题描述】:
我在一个文本文件中有一个基因名称列表,它们都在一列中。我想生成一个由逗号分隔的所有基因名称的字符串。我使用另一个线程来帮助我做到这一点,但我一直在每个名字之间有两个逗号。看起来它在每个名称之前和之后添加了一个逗号。任何指导将不胜感激!下面是代码sn-p!
File file = new File ("/Users/Maddy/Desktop/genelist.txt");
StringBuilder line = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader (new FileReader(file));
String text = null;
while ((text = reader.readLine()) !=null) {
line.append(text);
line.append(System.getProperty ("line.separator"));
//line.append(text);
//line.append(", ");
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
try {
if (reader !=null){
reader.close();
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println(line.toString());
String _input= new String(line.toString());
}
【问题讨论】:
-
您已经注释掉了
line.append(", ");,所以我认为这段代码不会在任何地方添加任何逗号。不要只是在此处粘贴这样的代码,它显然不会像您声称的那样做。 -
你的代码有什么问题?
-
对不起Kayaman,这是我第一个关于堆栈溢出的问题。我在尝试修复它时将其注释掉。
标签: java delimiter stringbuilder comma