小编use*_*095的帖子

使用固定宽度的列格式化文本表

我有一个包含商店信息的文件,我想将其排序为另一个文件,例如表格(在Excel中)。

文件 :

001     Tablets                        5      3
002     pens                           4      1
005     Computeres                     3      0
003     Bages                          2      1
004     USB                            4      0
Run Code Online (Sandbox Code Playgroud)

我写这段代码:

import java.util.*;
import java.io.*;

public class Sort {
public static void main(String [] args) throws IOException {
    FileInputStream fileinput = new FileInputStream("input.txt");
    FileOutputStream fileoutput = new FileOutputStream("output.txt");
    Scanner infile = new Scanner(fileinput);
    PrintWriter pw = new PrintWriter(fileoutput);
    int id, quantity, soldQuantity;
    String title;
    pw.println("ID\tTitle\t\t\tQuantity\tSoldQuantity");
    pw.println("");
    while(infile.hasNext()){
        id = infile.nextInt();
        title = infile.next();
        quantity = infile.nextInt();
        soldQuantity …
Run Code Online (Sandbox Code Playgroud)

java file

1
推荐指数
1
解决办法
6717
查看次数

标签 统计

file ×1

java ×1