2016-11-12 30 views
0

テキストファイルから読み込みしようとしていますが、このプログラムはテキストファイルのすべてのスペースの後に出力するのではなく、印刷したいのですがすべてのカンマの後に出てきます。私は別のクラスでこれらを呼び出すファイルから入力を取得する

package com.filetoscreen; 

import java.awt.Color; 
import java.awt.Font; 
import java.io.File; 
import java.util.Scanner; 

import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.SwingConstants; 

public class readFile { 


    private Scanner x; 

    public void openFile(){ 
     try{ 
      x = new Scanner(new File("input.txt")); 
     } 
     catch(Exception e){ 
      System.out.println("Couldn't find input.txt"); 
     } 
    } 

    public void readFile(){ 
     while(x.hasNext()){ 
      String a = x.next(); 
      System.out.print(a + " "); 


      JFrame frame = new JFrame("Game Name Generator"); 
      frame.setSize(1400, 1200); 
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
      frame.getContentPane().setBackground(Color.black); 
      JLabel label = new JLabel(a + " ", SwingConstants.CENTER); 
      frame.add(label); 
      label.setFont(new Font("SansSerif", Font.BOLD, 75)); 
      label.setForeground(Color.BLUE); 
      frame.setLocationRelativeTo(null); 
      frame.setResizable(true); 
      frame.setVisible(true); 
     } 
    } 

    public void closeFile(){ 
     x.close(); 
    } 
} 

ので、私はそこにそれを入れて気にしないだろう。

は、ここに私のコードです。スキャナの区切り文字として

+1

は、なぜあなたはそれぞれの新しいトークンを持つ新しいJFrameのを生成していますか? –

+0

@HovercraftFullOfEelsそれは彼らがすべてのものを振り返ることができるように、私はそれをスクロールする方法やそのようなものがわからない、もしあなたが知っていて、私が知りたいと言うことができるならば! –

答えて

1

セットカンマ:

final Scanner s = new Scanner(new StringReader("a b, c d, ef")); 
    s.useDelimiter(","); 
    while (s.hasNext()) { 
     System.out.println(s.next()); 
    } 
関連する問題