2016-05-07 13 views
0

私はJsoup HtmlパーサーでUEFAチームジェネレータを作っています。すべてはプロジェクトとして実行すると完全に動作しますが、jarファイルを作成するとファイルは作成されますが、書き込みは行われません。私はそれがいくつかの種類の安全だと聞いたが、私はそれを避けたい。何か案は?JARファイルはtxtを作成します。ファイルに書き込みません

コード:

public final class Generator extends JPanel { 

    JLabel label; 
    File file; 
    Font font; 
    ArrayList<String> urllist; 
    PrintWriter writer; 
    Document doc; 
    URL url; 
    JComboBox<String> seasons; // edited 
    String[] seas = {"1999-2000", "2000-2001", "2001-2002", "2002-2003", "2003-2004", "2004-2005", "2005-2006", "2006-2007", "2007-2008", "2008-2009", "2009-2010", "2014-2015", "2015-2016"}; 

    public Generator(int width, int height) { 

     setLayout(null); 
     setPreferredSize(new Dimension(width, height)); 
     seasons = new JComboBox<>(seas); 
     font = new Font("Verdana", Font.BOLD, 12); 

     label = new JLabel("Choose a season :"); 
     label.setFont(font); 
     label.setBounds(20, 10, 120, 30); 
     seasons.setBounds(150, 10, 100, 30); 
     add(seasons); 
     add(label); 

     urllist = new ArrayList<>(); 
     urllist.add("https://en.wikipedia.org/wiki/1999%E2%80%932000_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2000%E2%80%9301_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2001%E2%80%9302_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2002%E2%80%9303_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2003%E2%80%9304_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2004%E2%80%9305_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2005%E2%80%9306_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2006%E2%80%9307_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2007%E2%80%9308_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2008%E2%80%9309_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2009%E2%80%9310_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2014%E2%80%9315_UEFA_Champions_League_group_stage"); 
     urllist.add("https://en.wikipedia.org/wiki/2015%E2%80%9316_UEFA_Champions_League_group_stage"); 
     seasons.addActionListener(new GenerateHandler()); 

    } 

    public void cycle(int start, int end) { 

     for (int j = start; j < end; j++) { 

      Element table = doc.select("table.wikitable").get(j); 
      Elements rows = table.select("tr"); 

      for (int i = 1; i < 3; i++) { 
       writer.println(rows.get(i).select("td").select("a").get(1).attr("Title").replace(" (football)", "") + "," + rows.get(i).select("td").select("a").attr("Title")); 

      } 

     } 
     writer.close(); 

    } 

    public class GenerateHandler implements ActionListener { 

     @Override 
     public void actionPerformed(ActionEvent e) { 

      int i = seasons.getSelectedIndex(); 
      String foldername = "C:/Users/neutron/Desktop/data/"; 
      file = new File(foldername, seas[i] + ".txt"); 
      file.canWrite(); 

      try { 
       url = new URL(urllist.get(i)); 
      } catch (MalformedURLException ex) { 
       Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, null, ex); 
      } 
      try { 
       doc = Jsoup.parse(url, 3000); 
      } catch (IOException ex) { 
       Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, null, ex); 
      } 
      try { 
       writer = new PrintWriter(file, "UTF-8"); 
      } catch (FileNotFoundException | UnsupportedEncodingException ex) { 
       Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, null, ex); 
      } 

      if (i >= 0 && i < 3) { 
       cycle(1, 9); 
      } else if ((i > 2 && i < 4)|| (i > 10 && i < 13)) { 
       cycle(5, 13); 
      } else if (i == 8) { 
       cycle(2, 10); 
      } 
      else { 
       cycle(6, 14); 
      } 

     } 

    } 

} 

...それは警告やエラー

+0

関連するコード断片。 – rzo

+0

私は、それで十分ですか? – s0re

+0

さて、あなたがそれを走らせるときのあなたのアイディアは何ですか? – RealSkeptic

答えて

0

OK私は、一般的なJComboBoxの

代わりのJComboBox seasons;

することによってそれを解決して印刷できないjarファイルを構築します

私はそこに入れたJComboBox<String> seasons;

関連する問題