English 中文(简体)
妥善从My Java网络服务器获取图像
原标题:Getting an Image properly from My Java Web Server

我在贾瓦创建了一个简单的吉大港山区服务器。 当浏览器向我的网络服务器发送了GET申请时,请说。 目前,我的浏览器没有适当获得图像。

究竟必须确定哪些主干领域?

目前,我有日期、服务器、内容类型、内容-Length、链接。 我用:

fin = new FileInputStream(fileName);
contentLength = fin.available();

甲型异构体是正确的,因此不存在任何问题。

I write the file data using:

public void sendFile (FileInputStream fin, DataOutputStream out) 
{
    byte[] buffer = new byte[1024];
    int bytesRead;
    int strCnt = 0;
    try
    {
        int cnt = 0;
        while ((bytesRead = fin.read(buffer)) != -1)
        {
             out.write(buffer, 0, bytesRead);
        }
        fin.close();
    }
    catch (IOException ex)
    {

    }
}

这是我的 Chrome·布罗韦瑟所收到的资料。

Chrome Get

看来没有下载全部内容。

图像档案的实际规模为2.73KB。

如果没有一个主田被遗漏,那么会是什么问题?

问题回答

就像你一样,你没有发送所有数据。 添加面粉; out; before;在fin之前:

out.flush();
out.close();
fin.close();

我也建议你把你的数据集束总结成布图白。 从我的做法来看,在撰写文件时,与数据OutputStream相比,工作更快。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签