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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • 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.
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
 
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!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic