public static void main(String[] args) {
List lists=new ArrayList();
BufferedReader br = null;
String path="D:\\test\\src\\001.txt";
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(
new File(path)), "GBK"));
String line = null;
while ((line = br.readLine()) != null) {
lists.add(line);
}
//各元素按“---”分隔开拼接成一个字符串
String combiner=StringUtils.join(lists, "---");
System.out.println(combiner);
br.close();
} catch (Exception e) {
System.err.println("errors :" + e);
}
}
注意StringUtils用的包为import org.apache.commons.lang.StringUtils;
maven中央仓库可以下载到。