background image

 
e.writeObject("295");
    e.close();

    

 

 

执行 清单 2 

 

中的程序后,程序的执行目录中将出现一个名为 xmldata.xml 的文件。清单 

3 解释了新创建文件包含的内容。
    

 

清单 3. 

 

生成的 XML 数据

    < ?xml version="1.0" encoding="UTF-8"?>
    < java version="1.5.0_06" class="java.beans.XMLDecoder">
    < string>Josephine Bloggs< /string>
    < string>Internet< /string>
    < string>1mbps< /string>
    < string>Gbyte< /string>
    < string>295< /string>
    < /java>

    

 

 

您可以通过网络将 清单 3 

 — 

 

中的文件传输给等待状态中的客户机

使用 Java 技术即可

 

创建。清单 4 展示了一个简单的例子。
    

 

清单 4. 跨越网络传输文件

    byte[] bytes = new byte[BUFFER_SIZE];
    FileInputStream inputFile = null;
    try
    {
    File file = new File("xmldata.xml");
    if (file.exists())
    {
    inputFile = new FileInputStream(file);
    int ch = inputFile.read(bytes, 0, BUFFER_SIZE);
    while (ch != -1)
    {
    output.write(bytes, 0, ch);
    ch = inputFile.read(bytes, 0, BUFFER_SIZE);
    }
    }