This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

porting files from local node to server  RSS feed

 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I have to port files from local machines running on windows platform to a server running in solaris. The files should be ported in the same format as they are currently in ..
Using File Input / Output Streams throws an FileNotFound Exception.
Please help.
Advance Thanks,
Prabhu.V.C
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post your code and the exact error messages. We cannot help you from your simple description. A million things could go wrong.
 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the code ...
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FilePort extends HttpServlet
{
public void doGet (HttpServletRequestrequest,HttpServletResponseresponse) throws ServletException, IOException
{
PrintWriterout;
String title = "File Port Test Program ";
response.setContentType("text/html");
String mfilename=request.getParameter("mfilename");
// then write the data of the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<form name=PortFile action=http://iis-development:7777/pos/FilePort method=GET>");
out.println("<H3>" + title + "</H3>");
out.println("<BR>");
if(mfilename == null)
{
out.println("<input type=file name=mfilename>");
out.println("<BR><BR><BR>");
out.println("<input type=submit value='Port File ... '>");
}
else
{
int i=0;
out.println("File Name :: "+mfilename.trim());
try
{
//out.println("File Name :: "+mfilename+"<BR>");
String newpath="\\datadisk1\\pos\\";
FileInputStream fi=new FileInputStream(mfilename);
int last_slash_posn=mfilename.lastIndexOf("\\");
String newfilename=mfilename.substring(last_slash_posn+1,mfilename.length());
out.println("New File Name :: "+newfilename+"<BR>");
FileOutputStream fo=new FileOutputStream(newpath+newfilename);
while(i != -1)
{
i=fi.read();
if(i != -1)
{
fo.write((char) i);
}
}
fi.close();
fo.close();
out.println("<BR><BR><a href="+newpath+newfilename+"> Click To Open </a>");
}
catch(Exception ex)
{
out.println("Problem in File Porting ... "+ex);
}
}
out.println("</BODY></HTML>");
out.close();
}
}
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on your code, I assume you want to get file from a "upload" form and then dump it to a local directory. But the servlet API does not know how to handle uploaded file -- you cannot pretend it is a local file and open it.
You need third party libs that can handle file uploads for you. Have a look at this jguru FAQ:
http://www.jguru.com/faq/view.jsp?EID=160
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!