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

📄 showfile.java

📁 code to show file in the system
💻 JAVA
字号:
// Lab Assignment : 16
// Program to read Contents of File
// Name :Ishika Sarkar
// Roll no:IT 358 



import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class ShowFile implements ActionListener
{
	JFrame f;
	JLabel jl;
	JButton jb1;
	JTextField tf1,tf2;
	JTextArea ta1;
	ShowFile()
	{
		f=new JFrame("ShowFile");
		jl=new JLabel("Name of File");
		tf1=new JTextField(10);
		tf2=new JTextField(10);
		jb1=new JButton("Read");
		ta1=new JTextArea(30,30);
		f.setLayout(new FlowLayout());
		f.add(jl);
		f.add(tf1);
		f.add(jb1);
		f.add(ta1);
		jb1.addActionListener(this);
		f.setSize(200,200);
		f.setVisible(true);
	}
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource()==jb1)
		{
			String s=tf1.getText();
			try
			{
				FileReader fr=new FileReader(tf1.getText());
				BufferedReader br=new BufferedReader(fr);
				String str;
				while((str=br.readLine())!=null)
				{
			                     ta1.setText(ta1.getText()+str+"\n");
				}
				fr.close();
				br.close();
			}
			catch(Exception e1)
			{
				System.out.println("File not found");
			}
		}
	}
	public static void main(String args[])
	{
		ShowFile sf=new ShowFile();
	}
}

⌨️ 快捷键说明

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