急!!在线等!!!!!!!

dajiadebeibei9 2009-06-25 12:50:37
从D盘根目录下读取文本.txt,删除文本中单词之间多余的空格,就是两个单词之间只保留一个空格,并显示出来
删除空格的方法我会,但读取遇到问题
情况紧急 希望有人帮忙 谢谢
请给出完整代码!!!!
...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lkf15080 2009-06-25
  • 打赏
  • 举报
回复
File file = new File("d:/yourFile.txt");
if (!file.exists())
{
try
{
file.createNewFile();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try
{
BufferedReader br = new BufferedReader(new FileReader(file));
String line = br.readLine();
while (null != line)
{
System.out.println(line);
line = br.readLine();
}
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
Inhibitory 2009-06-25
  • 打赏
  • 举报
回复
public static void main(String[] args) {
BufferedReader reader = null;

try {
File file = new File("D:/xx.txt"); // Your txt file's path
reader = new BufferedReader(new FileReader(file));
String line = null;

while ((line = reader.readLine()) != null) {
// Removing the extra blank spaces.
// Operating the modified line.
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e2) {
}
}
}
}
sjkof 2009-06-25
  • 打赏
  • 举报
回复
读取遇到什么问题?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧