Java Reference
In-Depth Information
public void add(String name, File file) throws IOException
{
if (this.boundary != null)
{
boundary();
writeName(name);
write("; filename=\"");
write(file.getName());
write("\"");
newline();
write("Content-Type: ");
String type =
URLConnection.guessContentTypeFromName(file.getName());
if (type == null)
{
type = "application/octet-stream";
}
writeln(type);
newline();
byte[] buf = new byte[8192];
int nread;
InputStream in = new FileInputStream(file);
while ((nread = in.read(buf, 0, buf.length)) >= 0)
{
this.os.write(buf, 0, nread);
}
newline();
}
}
/**
* Add a regular text field to either a regular or
* multipart form.
*
* @param name
* The name of the field.
* @param value
* The value of the field.
* @throws IOException
* If any error occurs while writing.
*/
public void add(String name, String value) throws IOException
{
Search WWH ::




Custom Search