Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file upload in java....urgent..

 
karan, chopra
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.
regards
karan
 
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.io.*;
import java.lang.*;
import java.net.Socket;
import java.net.InetAddress;
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")) {
out.print(header);
out.println(cclen);
out.flush();
FileOutputStream fos = new FileOutputStream("/tmp/testfile");
while (totbytes < cclen)
{
bytesread = di.read(b, 0, 8192);
//out.println(bytesread);
//out.flush();
if (bytesread == -1)
break;
fos.write(b, 0, bytesread);
totbytes += bytesread;
}
fos.close();
out.print(trailer);
out.flush();
}
}
private static final String header = "<h1>Write in Progress</h1>\n<ul>\n";
private static final String trailer = "Finished</ul>\n";
}
regards
karan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic