Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

porting files from local node to server

 
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
 
author
Posts: 1436
5
Python TypeScript Java
  • 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
Posts: 1436
5
Python TypeScript Java
  • 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
 
Talk sense to a fool and he calls you foolish. -Euripides A foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic