11. 23. 4. 读写一个多边形 Reading Basic Data From an Object Stream
2011-10-10 19:38
453 查看
import java.awt.Polygon; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class ReadBasicData { public static void main(String[] args) { int[] x = new int[]{1,2,3}; int[] y = new int[]{4,5,6}; /* * 参数: * xpoints - X 坐标的数组 * ypoints - Y 坐标的数组 * npoints - 此 Polygon 中点的总数 */ Polygon polygon = new Polygon(x, y, x.length);//一个多边形 try{//从文件写入流套缓冲写入流再套上Object写入流 ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream( new FileOutputStream("Polygon.bin")));//用一个二进制格式 .bin 来存储 objectOut.writeObject(polygon);//写入一个多边形 objectOut.close(); }catch(IOException e){ e.printStackTrace(); } try{ ObjectInputStream objectIn = new ObjectInputStream(new BufferedInputStream( new FileInputStream("Polygon.bin"))); Polygon theLine = (Polygon)objectIn.readObject();//读出来再转成Polygon System.out.println(theLine); objectIn.close(); }catch(Exception e){ e.printStackTrace(); } } } /* * java.awt.Polygon@1270b73 */
相关文章推荐
- How to: Read Object Data from an XML File
- leetcode---Find Median from Data Stream---插入排序
- Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find
- (OK)(OK) Creating VMs from an existing VDI file in CLI (VBoxManage) in Fedora 23
- 295. Find Median from Data Stream&数据流中的中位数
- 295. Find Median from Data Stream
- Getting Started With OData Part 2: Building an OData Services from Any Data Source
- A Fast Method to Stream Data from Big Data Sources
- [转载]A problem when reading data from Excel
- GeneGAN: Learning Object Transfiguration and Attribute Subspace from Unpaired Data
- EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has cl
- [leetcode] 346. Moving Average from Data Stream 解题报告
- [leetcode295]Find Median from Data Stream
- Leetcode: Moving Average from Data Stream
- LeetCode Moving Average from Data Stream
- 一个不错的php类objectInfo,from oscommerce
- 在struts2 中 JSONArray.fromObject转化字符串的一个特殊用法,直接返回值
- How to: Reading an ini config file from a batch file
- #Paper Reading# Lifelong aspect extraction from big data knowledge engineering
- Leetcode Find Median from Data Stream