Data | database
Java in the writing of some graphical small program, sometimes to store a small amount of data, if the use of JDBC to connect the database, it will slow down the program, and, in addition, we can use Java files to save data in lieu of the database, so that not only can realize the function of storage, And without considering the frequent access to the data, you can define the file as an HTML file and display the stored data in a tabular format so that you can see the data directly in the Web page, and here is an example of a small file store data I wrote:
Import Java.awt.event.actionevent;import java.awt.event.actionlistener;import Java.sql.*;import Java.io.*;import javax.swing.*;p ublic class Filework extends JFrame implements ActionListener {JPanel p; JButton b0,b1,b2; JTable tab; Object my[][] = new OBJECT[50][3]; int a[]=new int[50]; int b[]=new int[50]; int j=0,rows=0; int k=0,shu=0; String Name,age; String title[] = {"Name", "Age", "height"}; BufferedReader in; int i = 0; Public Filework () {super ("Data Reincarnation"); This.setsize (300, 300); This.setdefaultcloseoperation (Jframe.exit_on_close); p = new JPanel (); tab = new JTable (my, title); B0 = new JButton ("Add"); B1 = new JButton ("open"); b2 = new JButton ("Save"); B1.addactionlistener (this); B2.addactionlistener (this); B0.addactionlistener (this); P.add (B0); P.add (B1); P.add (B2); This.getcontentpane (). Add (New JScrollPane (tab), "Center"); This.getcontentPane (). Add (P, "South"); This.setvisible (TRUE); public void FileOpen () {try{jfilechooser choose=new jfilechooser ("."); int Sis=choose.showopendialog (this); String name=choose.getselectedfile () + ""; if (sis==jfilechooser.approve_option) {in=new BufferedReader (new FileReader (name)); String Over=null; String Line; while ((Line=in.readline ())!=null) {over=over+line; for (int i=0;i<a.length;i++) {a[i]=over.indexof ("<td>") +4; B[i]=over.indexof ("</td>"); My[rows][k]=over.substring (A[i],b[i]); Over=over.substring (B[i]+4,over.length ()); k=k+1; if (k==3) {k=0;rows=rows+1;} }}catch (Exception IE) {}} public static void Main (string[] args) {filework filework = new Filework (); public void actionperformed (ActionEvent e) {if (e.getsource () = = B1) {FileOpen (); } if (E.getsource () = = b2) {jfilechooser save=new jfilechooser ("."); int result=save.showsavedialog (NULL); String s1=save.getselectedfile () + ""; if (result==jfilechooser.approve_option) {try {outputstreamwriter out = new OutputStreamWriter (new FileOutputStream (S1)); String s2= "