Java Code to Download files
Dear Sir,
I would kindly like to know whether any java classes are existent ,avliable for download ,which would provide the facility to
download a file from the server to the client machine.If not,kindly advise me on how to perform this task and kindly send me sample code if possible.
With regards
Santosh.
www.jscape.com has a great library for FTP as well as HTTP protocols. The library contains support for a host of other protocols as well. A trial version is available, but the licensed version is $95. I tried to find freeware for this type of functionality but none of them were very good. Shelling out the $95 ended up being a wise decision.
JP
Similar Messages
-
Code to download file from server
Hi
I need some code to download file from a server to a local machine.
Can anybody help me, PLEASE
Yohan ShikariIf i try this :
try
// path where the file is stord
// String idocPath = config.getServletContext().getInitParameter("idocPath");
String idocPath = "C:/";
String fileName = "http://194.98.51.253/utimaco.cer";
String filePath = idocPath + "\\" + fileName;
response.setContentType("APPLICATION/OCTET-STREAM");
String disHeader = "Attachment;Filename=" + fileName ;
response.setHeader("Content-Disposition", disHeader);
File file = new File(filePath);
FileInputStream fileInputStream = new FileInputStream(file);
int i;
while ((i=fileInputStream.read())!=-1)
response.getOutputStream().write(i);
response.getOutputStream().flush();
response.getOutputStream().close();
fileInputStream.close();
}catch(Exception e)
e.printStackTrace();
I don't understand the "type variable" of response !!!
Thomas -
What is wrong with the following Java servlet code that downloads files?
Hi,
I need urgent help.
This is the issue. I have a JSP code that calls a Java servlet class. This class is used to download files from the JSP page. The following is the piece of code that does the file download.
String pathOfFile = gsPath + "/" + gsFileName.substring(gsFileName.indexOf("~")+1);
File F = new File(pathOfFile);
res.setContentType("application/stream");
res.setHeader("Content-Disposition", "attachment; filename=" +gsFileName.trim());
This code works just fine with IE. However, when this is used with Netscape, the class name gets added to the original file name extension. For example, if the class name is 'FileRetriever' and the file being downloaded is originally named 'a.doc', the file gets a name of 'a.doc.FileRetriever' after download using Netscape or Mozilla.
One way to solve this is by adding the appropriate file type in the MIME settings in browser preference. However, this not a permanent solution.
Can somebody let me know the correct code to fix this issue?
Thanks for your time.We loose control of the file name once we pass the original file name to the input stream. When our code instructs Netscape to write the file on the local disk using an output stream, that is when Netscape/Mozilla adds this additional extension to the original file. So, essentially, we do not know about this additional extension.
Any ideas on how to resolve this?
Thanks. -
Hi!
I hope someone can help me with this.
I have done a program in Java-code and now I want to convert that code into an executable file that can be run on most computers. I have tried to convert the code to a JAR-file and then, using the program JSmooth, transform it into a exe-file. But, sad to say...it failed. Is JSmooth the way to do it or is there another better way?
Hope to get an answer.. :)
/ Berenuradd a Main-Class: yourclass line to a manifest file, and specify your manifest when you create the jar.
I.e.
Manifest-Version: 1.4
Main-Class: myClassSave that to manifest.mf or something like that.
Then,
jar -cvfm MyJar.jar manifest.mf [all files to include in jar]
done. -
Java code to download a webpage
Hi All,
I need to write a java code .In which i will pass some url (say www.forum.java.com\index.jsp) to it then it should downlaod all the data and images on this page to my local hard-disk. So that i should be able to see this locally also once it has been downloaded.
if some body has any idea then please lemme know.
Thanks
Akhil NagpalText but not images here ...
Takes the URL argument 'arg[0]' from the command line ie:-
prompt>java URLRead http://myhomepage.com >webpage.txt
import java.net.*;
import java.io.*;
class URLRead {
public static void main(String args[]) throws IOException{
URL u;
if (args[0] = null) {
u = new URL("http://forum.java.sun.com/index.html");
else {
u = new URL(args[0]);
try{
URLConnection uc = u.openConnection();
System.out.println(u.getPort() );
DataInputStream dis = new DataInputStream(uc.getInputStream());
String inputLine;
while ((inputLine = dis.readLine())!=null){
System.out.println(inputLine);
dis.close();
catch (MalformedURLException me) {
System.out.println("MalformedURLException: "+me);
} -
Java code to list files in Windows O/S by FIFO sequence
Hi,
I am new to java and working on a project which needs to list files from Windows O/S by FIFO sequence.
Here is the scenario,
One of the application logs/stores files in Windows System. After that files has to be moved to another files system on AS/400 by FIFO sequence.
I need to write java program to list files in Windows (by FIFO) and then move to different application running on AS/400.
I am using java.io.File class and method list() and could able to list all files. But, not able to list files by FIFO sequence.
I would appreciate to receive any thoughts implementing FIFO for listing files using java.
Thanks,
SivaDuplicate post, replied to here:
http://forum.java.sun.com/thread.jspa?threadID=5169767&messageID=9652068#9652068 -
Java code to upload file and place file on server directory
Hi,
Am a relatively new Java programmer. I need to add a functionality to a struts web application to allow users UPLOAD a file (using browse button). I need to read the file name,, do some other checks and eventually, upload the file to a server directory.
When do I start? Any good website for source code examples?
ThanksSee this http://jakarta.apache.org/commons/fileupload/
-
Running the Java Code from Batch File
Hi All,
I have run a code sucessfully in Eclipse and it uses Logging API from Java
When i try running the same program from batch file it throws error
java.io.IOException: Couldn't get lock for log\Properties_Log_16Sep2009_150229
at java.util.logging.FileHandler.openFiles(Unknown Source)
at java.util.logging.FileHandler.<init>(Unknown Source)
at com.adidas.SPM.LogMessage.<init>(LogMessage.java:26)
at com.adidas.SPM.MainApplication.initialize(MainApplication.java:51)
at com.adidas.SPM.MainApplication.main(MainApplication.java:102)
I am working on a windows systems the folder log has all the permission i have provided with all
Not sure why the code runs like this
The batch file is like below
set CURR_DIR=%CD%
cd %CURR_DIR%\bin
%CURR_DIR%\jre6\bin\java -classpath .;%CURR_DIR%\lib\FirstProject.jar com.test.MainApplication
echo %ERRORLEVEL% The Error Level
echo SUCCESS
GOTO END
:END
pause
Rgds
AdityaVikash.SunJava wrote:
According to me the problem is that there are many instances trying to access the same property file. Nothing wrong with that since they only are reading it.
The best way to do is that create a schedular in Windows that runs at some predefined interval (say 1 minute).Huh?
>
What will happen is if your program runs for more than a minute even then the new process will not start until old process is autaomatically killed. Please do not check this option if you want the program to exit normally.
If the Task is still running stop at this time
O_o -
Java code for Compressing files in UNIX
Hi ,
i am trying to compress files in unix but not seeing any change in size of packed file .any code please help.Hi ,
i am trying to compress files in unix but not seeing
any change in size of packed file .any code please
help.Does this question have anything to with Java whatsoever? If so how? And what types of files are you attempting to compress? If you are trying to compress a compress format the size difference will be... small if not actually worse then the originial. -
Java Code - to upload files on https
Hello:
I am really looking for a bean to upload and download flat files to a https server.
Thanks.Sanju,
If you wann to do transformation, Validation..That is message mappping & if you get a text file then You need to use FCC in Sender File adapter, If the Target system requires a different format example as text file and different structure then you need to use FCC in SOAP adapter and post to the webserver, If no message mapping needed then you can go ahead without FCC and drop the file with the help of HTTP / SOAP Adapter
Cheers
Agasthuri -
To download file but still the Save Dialog box still not show? Please help.
Hi All,
Below is my full code to download file but still the Save Dialog box still not show..
<%@ taglib prefix="cs" uri="futuretense_cs/ftcs1_0.tld"
%><%@ taglib prefix="asset" uri="futuretense_cs/asset.tld"
%><%@ taglib prefix="assetset" uri="futuretense_cs/assetset.tld"
%><%@ taglib prefix="commercecontext" uri="futuretense_cs/commercecontext.tld"
%><%@ taglib prefix="ics" uri="futuretense_cs/ics.tld"
%><%@ taglib prefix="listobject" uri="futuretense_cs/listobject.tld"
%><%@ taglib prefix="render" uri="futuretense_cs/render.tld"
%><%@ taglib prefix="siteplan" uri="futuretense_cs/siteplan.tld"
%><%@ taglib prefix="searchstate" uri="futuretense_cs/searchstate.tld"
%><%@ taglib prefix="locale" uri="futuretense_cs/locale1.tld"
%><%@ taglib prefix="dateformat" uri="futuretense_cs/dateformat.tld"
%><%@ taglib prefix="blobservice" uri="futuretense_cs/blobservice.tld"
%><%@ taglib prefix="satellite" uri="futuretense_cs/satellite.tld"
%><%@ taglib prefix="date" uri="futuretense_cs/date.tld"
%><%@ page import="COM.FutureTense.Interfaces.*,
COM.FutureTense.Util.ftMessage,
COM.FutureTense.Util.ftErrors"
%><%@ page import="COM.FutureTense.Interfaces.*,
COM.FutureTense.Util.ftMessage,
COM.FutureTense.Util.ftErrors"
%>
<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="java.io.File" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.io.FileInputStream" %>
<cs:ftcs><%-- france/test_template
INPUT
OUTPUT
--%>
<%-- Record dependencies for the Template --%>
<ics:if condition='<%=ics.GetVar("tid")!=null%>'><ics:then><render:logdep cid='<%=ics.GetVar("tid")%>' c="Template"/></ics:then></ics:if>
<%
String fileToFind = request.getParameter("file");
if(fileToFind == null) return;
File fname = new File(fileToFind);
System.out.println("Save As: "+fname.getName() );
if(!fname.exists()) return;
FileInputStream istr = null;
response.setContentType("application/octet-stream;charset=ISO-8859-1");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fname.getName() + "\";");
try {
istr = new FileInputStream(fname);
int curByte=-1;
while( (curByte=istr.read()) !=-1){
out.write(curByte);
out.flush();
} catch(Exception ex){
ex.printStackTrace(System.out);
} finally{
try {
if(istr!=null) istr.close();
} catch(Exception ex){
System.out.println("Major Error Releasing Streams: "+ex.toString());
try {
response.flushBuffer();
} catch(Exception ex){
System.out.println("Error flushing the Response: "+ex.toString());
%>
</cs:ftcs>
Can anybody help me with this??? What is lacking...
Thank you in advance.Put this code into a servlet rather than a JSP.
JSP are for returning text based HTML pages. It adds extra carriage returns into the response that will corrupt the file, and prevent the dialog showing up.
This code is much better off being in a servlet
If you are using a FileInputStream, you should be using a ServletOutputStream rather than the JSP writer: response.getOutputStream()
When dealing with file input in a JSP/Servlet you should use the methods of ServletContext. getRealPath() turns a website relative file into a real location on disk. getResourceAsStream() opens the file for you. getResourceAsStream() is more reliable as it will work even if the web app is deployed in a packed WAR.
Cheers,
evnafets -
Tcode for downloading file from BW server
hi
can nay tell me what is the T-CODE to download file from BW server to my PC.
REMOVED
regards
sampathThere isn't a transaction.
You can see the example report to execute ftp on BW server.
server to server
or
client to server.
the reports are named like:
rsftp001
rsftp002
rsftp011
Regards,
Sergio -
Regarding use of java code inside javascript
Hi ,
I have doubt regarding how to use java code inside javascript,
i am giving my application code here
<%@page import="java.util.*"%>
<%@ page import="com.suuny.sard.pmt.pat.*"%>
<SCRIPT LANGUAGE="JavaScript">
function fun(){
var ac=document.login.Projectname.options[document.login.Projectname.selectedIndex].value;
var c = document.login.task1.value;
alert(ac);
alert(c);
return true;
</SCRIPT>
<form name="login" action="/pmt/jsp/Leavemanagement/Leave_Ems_HomePage.jsp" method="get" encType="x-www-form-encoded" >
<table width="100%" Align="Center" cellspacing="0" cellpadding="0" border="0">
<tr class="tablerow"><td colspan="6" align="center"><font class="pagehead" align="center">Create Tasks</font></td></tr>
<tr class="tableheader">
<th>Project
<th>Task-Id
<th>TaskName
<th>Assigned To
<th>description
<th>Milestone
</tr>
<%
for(int i=1;i<2;i++){%>
<tr class="tablerow"><td align="center">
<select class="SELECT" NAME="Projectname" VALUE=" " onchange="return fun();" >
<!--<option value=""> </option>-->
<%
ArrayList ar =null;
ArrayList projectids=null;
Hashtable ht = new Hashtable();
ProjectNames pnames=new ProjectNames();
ht = pnames.getProjectNames();
ar=(ArrayList)ht.get("projects");
projectids=(ArrayList)ht.get("projectIds");
for(int j=0;j<ar.size();j++){
out.println("<option value=\""+projectids.get(j)+"\">"+ar.get(j)+"</option>");
%>
</select>
<%
out.println("<td align=\"center\"><input type=\"text\" name=\"task"+i+"\"value=\"\" size=\"25\"></td>");
out.println("<td align=\"center\"><input type=\"text\" name=\"taskname"+i+"\"value=\"\" size=\"25\"></td>");
%>
<td align="center">
<select class="SELECT" NAME="Projectname1" VALUE=" ">
<!--<option value=""> </option>-->
<%
ArrayList ar1 =null;
ar1 = pnames.getProjectResource("VXML02");
for(int j=0;j<ar1.size();j++){
out.println("<option value=\""+ar1.get(j)+"\">"+ar1.get(j)+"</option>");
%>
</select>
<%
out.println("<td align=\"center\"><input type=\"text\" name=\"description"+i+"\"value=\"\" size=\"25\"></td>");
out.println("<td align=\"center\"><input type=\"text\" name=\"milestone"+i+"\"value=\"\" size=\"25\"></td><tr>");
out.println("<tr class=\"tablerow\"><td colspan=\"6\" align=\"center\"><input class=\"txtbuttonsmall\" type=\"submit\" value=\"save\"></td>");
%>
</Table>
</form>
My question is :
I selected one project from first combo box ,i need project members corresponding to the project.
In my code "pnames.getProjectResource("VXML02");" in this function iam passing one static projrct value,but i need dynamically selected project from first combo box(<select class="SELECT" NAME="Projectname" VALUE=" " onchange="return fun();" >),so please help me guys.Hi Marco,
I "executed" some java code within XSLs file. I have quoted the word executed because I didn't really run java code, but I used a simply trick that I describe you below.
Into your XSLs put an iframe which is hided (it has an height of 0 pixel). As src of the iframe put the address of a portal component which execute your code (in my case calculate some PCD URL of some pages into a defined role). As result of component execution, I use the response.write method in order to execute some jscript code, which is able to interact with the HTML generated by XSLs files, for example in my case response.write put the PCD URL into a drop down list placed into the "edit" form.
This works fine. I don't know if is suitable also for your case, anyway could be a hint, but pay attention to Roland's recommendations.
Ciao
Roberto -
Use of Java Code within the generated XML Forms Stylesheets
Hello,
is the use of Java-Code possible with the XSL-Files generated by XML-Forms, as possible in standard XSLs? I know that this would mean a modification.
kind regards,
MarcoHi Marco,
I "executed" some java code within XSLs file. I have quoted the word executed because I didn't really run java code, but I used a simply trick that I describe you below.
Into your XSLs put an iframe which is hided (it has an height of 0 pixel). As src of the iframe put the address of a portal component which execute your code (in my case calculate some PCD URL of some pages into a defined role). As result of component execution, I use the response.write method in order to execute some jscript code, which is able to interact with the HTML generated by XSLs files, for example in my case response.write put the PCD URL into a drop down list placed into the "edit" form.
This works fine. I don't know if is suitable also for your case, anyway could be a hint, but pay attention to Roland's recommendations.
Ciao
Roberto -
Hi,
I want to generate Java code from XMI files. Is JMI the right way? If so: I found the JMI specification but not the classes. Can anybody tell me where they are hidden?
Thanks in advance for your help.
Philyou can find some info about a project (MDR) that uses jmi here:
http://mdr.netbeans.org/architecture.html#jmi
http://mdr.netbeans.org/docs.html
As I understand it, jmi provides a standard way to generate java interfaces to MOF models. So code generation focused on jmi is usually only interesting for metamodel repository developers.
If you like the idea of JMI, you could build on top of a tool that is JMI compliant. You could extend MDR. Or you could extend a template based tool like AndroMDA,http://www.andromda.org, which itself is built on MDR.
Or, you could forget MOF and JMI and work with Eclipse EMF which provides java generation capabilities. http://www.eclipse.org/emf/
If you want to generate from xmi directly then you are looking at building your own tool using DOM or XSLT etc. but it would be better to read the xmi into a metamodelling tool/repository and use the services they provide.
Anyway you need to get your xmi from somewhere, and that source will restrict your choice for code generation.
You could use/buy a tool like Together, but it doesn't look like you are interested in that.
Maybe you are looking for
-
Hi, We have 4 regions like UK, India, US, Japan.. when ever UK users logins to OBIEE the dashboard should get defaulted to UK region and user should see UK reports only. Similarly if a Japan, US users logins he should see reports corresponding to his
-
please help!! i've recently updated to the latest itunes version. after much hassle in doing so, it now tells me that the registry settings for importing or burning CD's/DVD's doesn't work and that i should reinstall itunes. i,ve done that from the w
-
FaceTime can't detect a camera (Mac Pro)
I have just taken delivery of a new Mac Pro. I am running OSX 10.9.1. On my old iMac, facetime happily used the on board iSight camera for video, but now when I try to use my Philips webcan via USB (plugged directly into the Mac Pro, not via a USB hu
-
Create Apple TV version?
Some .mpg video files played fine on my computer (10.5.5), but my Apple TV said it cannot play it. So I use "create Apple TV version" inside iTunes, and created a new version. The new version does play in Apple TV, but without sound! I changed .mpg t
-
Hi, I have been trying to add breadcrumbs to my pages using dreamweaver 8. I am aware that there are templates in snippets. but it appears as if the only way of using them is to place them on every page, manually changing the coding of each. Is this