wo kao, your prog is so strong. try uncomment your souce code of 
public void ZS(....String s="/*adsfasdfs*";
after your prog, s=".Qiang. Gao. LiHai. Peifu

解决方案 »

  1.   

    所有源码:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    import java.io.*;
    import java.util.Vector;
    import java.util.Enumeration;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    public class Frame1 extends JFrame {
      Vector vecList=new Vector();
      private JPanel contentPane;
      private XYLayout xYLayout1 = new XYLayout();
      private JButton jButton1 = new JButton();
      private JTextField tf = new JTextField();
      private JButton jbutton2 = new JButton();
      private JScrollPane jScrollPane1 = new JScrollPane();
      private JTextArea jt = new JTextArea();
      private JLabel jLabel1 = new JLabel();
      private JLabel jLabel2 = new JLabel();  //Construct the frame
      public Frame1() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }
      //Component initialization
      private void jbInit() throws Exception  {
        //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
        contentPane = (JPanel) this.getContentPane();
        jButton1.setToolTipText("");
        jButton1.setText("开始处理");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        contentPane.setLayout(xYLayout1);
        this.setSize(new Dimension(400, 287));
        this.setTitle("删除文件注释(岳辉科技网)http://yuehui.cn.gs");
        jbutton2.setText("获取文件");
        jbutton2.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jbutton2_actionPerformed(e);
          }
        });
        jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        jLabel1.setToolTipText("");
        jLabel1.setText("路径:");
        jLabel2.setForeground(Color.red);
        jLabel2.setToolTipText("");
        jLabel2.setText("声明:本程序仅作学习用途,如在使用过程中造成任何损失,本站不负责!");
        contentPane.add(tf,    new XYConstraints(53, 24, 235, -1));
        contentPane.add(jLabel1, new XYConstraints(17, 27, -1, -1));
        contentPane.add(jScrollPane1,                         new XYConstraints(16, 50, 364, 96));
        contentPane.add(jbutton2,  new XYConstraints(291, 19, 87, -1));
        contentPane.add(jButton1, new XYConstraints(163, 156, -1, -1));
        contentPane.add(jLabel2,   new XYConstraints(16, 202, 374, -1));
        jScrollPane1.getViewport().add(jt, null);
      }
      //Overridden so we can exit when window is closed
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }
    //------------------------------------------------------------------------------
    //开始循环处理已获取的文件名
      void jButton1_actionPerformed(ActionEvent e) {
     try{
      String sFileName="";
      Enumeration ew=vecList.elements();
      while (ew.hasMoreElements()) {
             sFileName= ew.nextElement().toString();//取得文件名
             ZS(sFileName);//删除注释         }
           JOptionPane.showConfirmDialog(this,"处理完成。","提示",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);
      }
      catch(Exception er){
        JOptionPane.showConfirmDialog(this,"处理失败。","提示",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);  }
      }
    //------------------------------------------------------------------------------
    //删除注释的核心代码
    public void ZS(String fileStr)
    {
      try{
      Vector vec=new Vector();
      String str="",tm="",mm="";
      BufferedReader br = new BufferedReader( new FileReader(fileStr));
      boolean bol=false;
      while( null != (str = br.readLine() ) )
      {
        if ((str.indexOf("/*")>=0)&&((bol==false)))
        {
          if (str.indexOf("*/")>0)
          {
            bol=false;
            vec.addElement(str.substring(0,str.indexOf("/*"))+str.substring(str.indexOf("*/")+2,str.length()));
          }
           else
               {
                 bol=true;
                  mm=str.substring(0,str.indexOf("/*"));
                  if (!(mm.trim().equals("")))
                      vec.addElement(mm);
               }
        }
        else if (bol==true)
             {
               if (str.indexOf("*/")>=0)
               {
                   bol=false;
                   mm=str.substring(str.indexOf("*/")+2,str.length());
                   if (!mm.trim().equals(""))
                      vec.addElement(mm);
               }
             }
             else if (str.indexOf("//")>=0)
                  {
                     tm=str.substring(0,str.indexOf("//"));
                     if (!tm.trim().equals(""))
                        vec.addElement(tm);
                  }
                  else
                  {
                      vec.addElement(str);
                  }
     }
      br.close();
      File fName=new File(fileStr);
      FileWriter in=new  FileWriter(fName);
      String ssss="";
      Enumeration ew=vec.elements();         while (ew.hasMoreElements()) {
               ssss= ew.nextElement().toString();
               in.write(ssss+"\n");
             }  in.close();
      vec.clear();  }catch(Exception ee){
        JOptionPane.showConfirmDialog(this,"处理失败。","提示",JOptionPane.CLOSED_OPTION,JOptionPane.INFORMATION_MESSAGE);
      }}//------------------------------------------------------------------------------
    //读取指定目录的所有文件
     void jbutton2_actionPerformed(ActionEvent e)  {
         writeTxt(tf.getText());
      }
    //------------------------------------------------------------------------------
    //以下读取指定目录内文件是由:abcpl(蓝鸟) 网友提供,在此谢谢了
      void writeTxt(String dire)
     {
       File file = new File(dire);
       jt.setText("");
       String[] file_temp=null;
       if(file.isDirectory())
       {
         file_temp = file.list();
         for(int i = 0;i < file_temp.length;i++)
         {       if (file_temp[i].toLowerCase().toString().indexOf(".")>=0)
           {         if (dire.trim().length()>3)
             {
                jt.append(file.getPath()+"\\"+file_temp[i].toLowerCase()+"\n");
                vecList.add(file.getPath()+"\\"+file_temp[i].toLowerCase());
             }
             else
             {
                jt.append(file.getPath()+file_temp[i].toLowerCase()+"\n");
                vecList.add(file.getPath()+"\\"+file_temp[i].toLowerCase());
             }
           }
         }
       }
       else if(file.isFile())
       {
          ;
       }
       else
       {
           jt.setText("请输入目录");   }
     }