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

📄 例10.txt

📁 输入输出流 综合应用实例 可是自学者更轻松的理解 输入输出流的知识
💻 TXT
字号:
import java.io.*;
class Goods implements Serializable 
{  
   String name=null;
   double unitPrice;
   Goods(String name,double unitPrice)
     {  
         this.name=name;
         this.unitPrice=unitPrice;
     }
   public void setUnitPrice(double unitPrice)
   {  
         this.unitPrice=unitPrice;
   }
   public void setName(String name)
   {  
         this.name=name;
   }
   public String getName()
   {
         return name;
   }
   public double getUnitPrice()
   {
         return unitPrice;
   }
}
public class Example
{ 
   public static void main(String args[ ])
   {  
      Goods TV1=new  Goods("HaierTV",3468);
      try
      {  
             FileOutputStream   fileOut=new FileOutputStream("a.txt");
             ObjectOutputStream  objectOut=new ObjectOutputStream(fileOut);
             objectOut.writeObject(TV1);  
             FileInputStream fileIn=new FileInputStream("a.txt");
             ObjectInputStream objectIn=new ObjectInputStream(fileIn);
             Goods TV2=(Goods)objectIn.readObject();
             TV2.setUnitPrice(8888);
             TV2.setName("GreatWall");
             System.out.printf("\nTv1:%s,%f",TV1.getName(),TV1.getUnitPrice());
             System.out.printf("\nTv2:%s,%f",TV2.getName(),TV2.getUnitPrice());
      }
      catch(Exception event)
      {  
         System.out.println(event);
      }
   }
}

⌨️ 快捷键说明

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