我从一个站点获取源代码并将代码放入一个字符串中,看起来像这样:
501252,110,34496
331550,30,14114
403186,1,18
325033,31,15750
460287,14,2384
286659,11,1366
419439,1,67
678464,1,0
505044,1,70
522192,1,75
454391,1,0
504858,1,20
505396,1,40
469927,1,0
336670,2,155
392887,5,437
403568,1,0
488324,1,0
524031,1,0
429226,1,0
389668,1,0
383021,1,0
384599,1,0
363131,1,0
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
-1,-1
我想拆分每个数字,并将它们保存在自己的字符串中,我该怎么做呢?
当前代码:(如果有帮助吗?)
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class dfgdfg {
static String username;
static JTextField USERNAME = new JTextField();
static String pooo;
static JPanel panel;
static JFrame jframe;
static JButton button;
static String line;
public static void main(String args[]) throws Exception {
GUI();
}
public static void getSource() {
URL url;
InputStream is = null;
BufferedReader br;
try {
url = new URL(
"http://services.runescape.com/m=hiscore_oldschool/index_lite.ws?player="+username);
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
public static void GUI() {
jframe = new JFrame("HighscoreLookup");
panel = new JPanel();
USERNAME = new JTextField("Enter Username");
button = new JButton("START");
jframe.setPreferredSize(new Dimension(300, 300));
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
jframe.add(panel);
panel.add(USERNAME);
panel.add(button);
panel.setBackground(Color.CYAN);
button.setVisible(true);
USERNAME.setSize(100,50);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
username = USERNAME.getText().toString();
System.out.println(username);
getSource();
}
});
jframe.pack();
}
}