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

📄 writecountryinfo.java

📁 java源程序 对初学者有很大的帮助 从简单到复杂
💻 JAVA
字号:
//********************************************************************
//  WriteCountryInfo.java       Author: Lewis/Loftus
//
//  Demonstrates object serialization.
//********************************************************************

import java.io.*;

public class WriteCountryInfo
{
   //-----------------------------------------------------------------
   //  Creates several objects, prints them to standard output, and
   /// serializes them to a file.
   //-----------------------------------------------------------------
   public static void main (String[] args) throws IOException
   {
      FileOutputStream file = new FileOutputStream ("countries.dat");
      ObjectOutputStream outStream = new ObjectOutputStream (file);

      CountryInfo[] countries = new CountryInfo[5];

      countries[0] = new CountryInfo ("United States of America",
                     "USA", "Washington, D.C.", 9629091L, 278058900L);
      countries[1] = new CountryInfo ("Russia", "RUS", "Moscow",
                     17075200L, 145470200L);
      countries[2] = new CountryInfo ("Italy", "ITA", "Rome",
                     301230L, 57679800L);
      countries[3] = new CountryInfo ("Sweden", "SWE", "Stockholm",
                     449964L, 8875100L);
      countries[4] = new CountryInfo ("Poland", "POL", "Warsaw",
                     312685L, 38633900L);

      int scan;

      //  Print the objects
      for (scan = 0; scan < countries.length; scan++)
         System.out.println (countries[scan]);

      //  Serialize the objects to a file
      for (scan = 0; scan < countries.length; scan++)
         outStream.writeObject (countries[scan]);
   }
}

⌨️ 快捷键说明

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