• 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) {
      }
      }

  • 相关阅读:
    Core Text 实现富文本显示
    音视频直播服务平台总结
    WWDC2017那些事
    Swift网络请求(Moya篇)
    [转贴]孙正耀退休感言
    不要让专业限制了你的高度
    你会搞科研吗?
    上传服务端
    AysnTask+HttpClient实现上传
    TextView改变颜色
  • 原文地址:https://www.cnblogs.com/lansetuerqi/p/5463433.html
Copyright © 2020-2023  润新知