java如何修改文件在窗口中_java如何修改文件里的内容

stats.datWillyWonk,o,o,h,o,o,o,o,h,w,o,o,o,o,s,h,o,hShariJones,h,o,o,s,s,h,o,o,o,h,o,o,o,oBarryBands,h,h,w,o,o,o,w,h,o,o,h,h,o,o,w,w,w,h,o,oSallySlugger,o,h,h,o,o,h,h,wMi...

stats.dat

Willy Wonk,o,o,h,o,o,o,o,h,w,o,o,o,o,s,h,o,h

Shari Jones,h,o,o,s,s,h,o,o,o,h,o,o,o,o

Barry Bands,h,h,w,o,o,o,w,h,o,o,h,h,o,o,w,w,w,h,o,o

Sally Slugger,o,h,h,o,o,h,h,w

Missy Lots,o,o,s,o,o,w,o,o,o

Joe Jones,o,h,o,o,o,o,h,h,o,o,o,o,w,o,o,o,h,o,h,h

Larry Loop,w,s,o,o,o,h,o,o,h,s,o,o,o,h,h

Sarah Swift,o,o,o,o,h,h,w,o,o,o

Bill Bird,h,o,h,o,h,w,o,o,o,h,s,s,h,o,o,o,o,o,o

Don Daring,o,o,h,h,o,o,h,o,h,o,o,o,o,o,o,h

Jill Jet,o,s,s,h,o,o,h,h,o,o,o,h,o,h,w,o,o,h,h,o

以上是我想要修改的文件。

import java.util.Scanner;

import java.io.*;

public class BaseballStats

{

public static void main (String[] args) throws IOException {

Scanner fileScan, lineScan;

String fileName;

Scanner scan = new Scanner(System.in);

System.out.print ("Enter the name of the input file: ");

fileName = scan.nextLine();

fileScan = new Scanner(new File(fileName));

fileName.replace(' ', ',');

while(fileScan.hasNext())

{

fileName=fileScan.next();

System.out.println("fileName:"+fileName);

lineScan=new Scanner(fileName);

lineScan.useDelimiter(",");

while(lineScan.hasNext())

System.out.print("\t"+lineScan.next());

System.out.println("");

}

}

}

我用这段代码运行出来的结果会把英文名分开,请问如何修改代码才可以正常输出,比如说第一个输出结果如下:

fileName:Willy

Willy

fileName:Wonk,o,o,h,o,o,o,o,h,w,o,o,o,o,s,h,o,h

Wonkoohoooohwooooshoh

我想要输出Willy Wonk在一行里面这样的结果

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值