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

📄 f.java

📁 实现一个简单的文本编辑器
💻 JAVA
字号:
import java.io.*;

class KeyInput
{
	public static String read()
	{
		String s=null;
		try
		{
			InputStreamReader in=new InputStreamReader(System.in);
			BufferedReader br=new BufferedReader(in);			
			s=br.readLine();
		}
		catch(IOException e)
		{
			System.out.println("Error1:"+e);
			System.exit(-1);
		}
		finally
		{
			return s;
		}
			
	}
}
public class f
{
	private File file;
	public f(String filename)
	{
		try
		{
			file=new File(filename);
		}
		catch(IndexOutOfBoundsException e)
		{
			System.out.println("Error2:"+e);
		}		
	}
	/*public String readFile()
	{
		String str="";
		try
		{
			FileInputStream in=new FileInputStream(file);
			DataInputStream input=new DataInputStream(in);
			String b="";
			while((b=input.readLine())!=null)
			{
				str+=b+"\r\n";
			}
			input.close();
		}		
		catch(IOException e)
		{
			System.out.println("Error4:"+e);
		}
		finally
		{
			return str;
		}
	}
	*/
	public void WriteFile()
	{
		try
		{
			String s="";
			//String str="";
			//str=readFile();	
			FileOutputStream out=new FileOutputStream(file);
			DataOutputStream output=new DataOutputStream(out);
			//output.write(str.getBytes());
			System.out.print("请输入要存储的字符串,stop结束:");	
			s=KeyInput.read();
			while(!s.equals("stop"))
			{	
				s+="\r\n";
				output.write(s.getBytes());
				System.out.print("请输入要存储的字符串,stop结束:");
				s=KeyInput.read();
			}
			output.close();	
		}
		catch(FileNotFoundException e)
		{
			System.out.println("Error:"+e);	
		}		
		catch(IOException e)
		{
			System.out.println("Error5:"+e);
		}		
	}
	public static void main(String args[])
	{
		f e=new f(args[0]);
		System.out.print("当前文件的字符流:");
		//System.out.print(e.readFile());
		e.WriteFile();
		//System.out.print("写入后文件的字符流:");
		//System.out.print(e.readFile());
	}
}

⌨️ 快捷键说明

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