⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javafile.java

📁 用java编写的IDE程序示例
💻 JAVA
字号:
/*
 * Created on 2004-5-26
 */
package yuchifang.javaIDE.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author yuchifang
 */
public class JavaFile
{
  private String content="";
  private String filePath;
  private String fileName;
  private static int fileCount = 0;
  
  /**
   * @param file 要打开的文件
   */
  public JavaFile(File file)
  {
    fileCount++;
    if (file == null)
    {
       fileName = "NoName" + fileCount;
       return;
    } 
    
    fileName = file.getName();
    
    try
    {
      filePath = file.getCanonicalPath();
    } catch (IOException e)
    {
      e.printStackTrace();
      filePath = null;
    }
    
    try
    {
      BufferedReader in = new BufferedReader(new FileReader(file));
      String line = null;
      StringBuffer sb = new StringBuffer();
      while ((line = in.readLine()) != null)
      {
        sb.append(line);
        sb.append("\r\n");
      }
      content = sb.toString();
      in.close();
    } catch (FileNotFoundException e)
    {
      e.printStackTrace();
      content = "";
    } catch (IOException e)
    {
      e.printStackTrace();
    }
  }//JavaFile(File)
  
	/**
	 * @return 文件路径名
	 */
	public String getFilePath()
	{
		return filePath;
	}

  public String getFileName()
  {
    return fileName;
  }

  public void save()
  {
    saveAs(new File(filePath));
  }
  
  public void saveAs(File file)
  {
    try
    {
      BufferedWriter out = new BufferedWriter(new FileWriter(file));
      out.write(content);
      out.flush();
      out.close();
      
      filePath = file.getAbsolutePath();
      fileName = file.getName();
    } catch (FileNotFoundException e)
    {
      e.printStackTrace();
      content = "";
    } catch (IOException e)
    {
      e.printStackTrace();
    }
  }

	/**
	 * @param string 文件路径
	 */
	public void setFilePath(String string)
	{
		filePath = string;
    //##save file
	}

	/**
	 * @return 文件内容
	 */
	public String getContent()
	{
		return content;
	}

	/**
	 * @param string 文件内容
	 */
	public void setContent(String string)
	{
		content = string;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -