Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

file upload in java....urgent..

Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
can anyone please tell me how to upload a file from hard disc to a server in java.a piece of sample code would be of great help.
karan, chopra
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,
i found the following piece of code but it gives me errors in the first two import statements and the getOutputStream statemets,it says "cannot resolve symbol",does it mean that i got to have some netscape class files in order to run it?please help me out..its urgent..i would really appreciate it.
import netscape.server.applet.HttpApplet;
import netscape.server.applet.ServerApplet;
import java.lang.*;
import java.util.Hashtable;
import java.util.Enumeration;
class UploadApplet extends HttpApplet {
public void run() throws Exception {
int cclen, bytesread = 0;
int totbytes = 0;
int bytesremain = 0;
int bytesavail = 0;
String line;
byte b[] = new byte[9192];
line = getHeader("content-length");
cclen = Integer.parseInt(line);
PrintStream out = getOutputStream();
InputStream is = getInputStream();
DataInputStream di = new DataInputStream(is);
if (returnNormalResponse("text/plain")) {
FileOutputStream fos = new FileOutputStream("/tmp/testfile");
while (totbytes < cclen)
bytesread =, 0, 8192);
if (bytesread == -1)
fos.write(b, 0, bytesread);
totbytes += bytesread;
private static final String header = "<h1>Write in Progress</h1>\n<ul>\n";
private static final String trailer = "Finished</ul>\n";
The problems of the world fade way as you eat a piece of pie. This tiny ad has never known problems:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic