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在一行里面这样的结果
展开