zoukankan      html  css  js  c++  java
  • swing

    //通过swing控件读取文件

    private static void chooseFile() {
      JFileChooser jfc = new JFileChooser();// 初始化文件选择器
      FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT","txt");// 设置文件过滤,TXT为提示用户选择文件类型,txt为文件过滤后缀
      jfc.setFileFilter(filter);// 将文件过滤加载到选择器中
      int returnVal = jfc.showOpenDialog(null);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
      // 获得打开的文件
      File file = jfc.getSelectedFile();
      File out = new File(file.getParent() + "\jiagkun.txt");
      try {
        InputStreamReader in = new InputStreamReader(
        new FileInputStream(file), "UTF-8");
        BufferedReader buff = new BufferedReader(in);
        BufferedWriter write = new BufferedWriter(new FileWriter(out));
        String text = null;
        while ((text = buff.readLine()) != null) {
          write.write(text + " ");
        }
        buff.close();
        write.close();
      } catch (FileNotFoundException e1) {
      } catch (UnsupportedEncodingException e1) {
      } catch (IOException e1) {
      }
      }

  • 相关阅读:
    jquery 選擇器
    jquery 語法
    jQuery 簡介
    js cookies
    基本数据类型
    python----编程语言介绍
    Python---计算机基础
    复习os模块常用的一些操作
    模块的初识
    模块和包
  • 原文地址:https://www.cnblogs.com/lansetuerqi/p/5463433.html
Copyright © 2011-2022 走看看