473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

File download to client... new Java user

yarbrough40
320 100+
I'm a seasoned .net guy - new to Java. I'm Trying to do the simplest of things but can't figure it out. In my web form I want to create a csv file (from a json string) and present it to the user to download (I do not want to specify a directory - let the user do that)

I have this working code which writes my file to a directory but really all I want is for it to download in the browser - NOT write to a filepath. How is this done?

Expand|Select|Wrap|Line Numbers
  1.      JSONObject output = new JSONObject(jsonString);
  2.      JSONArray docs = output.getJSONArray("myData");
  3.      File file=new File("C:\\Work\\fromJSON.csv"); //DON'T WANT TO SPECIFY A DIRECTORY
  4.      String csv = CDL.toString(docs);
  5.      FileUtils.writeStringToFile(file, csv);
  6.  
Oct 30 '14 #1

✓ answered by yarbrough40

I figured it out finally. I am using this within a Wavemaker project. Wavemaker has a bool property I did not see called "DownloadFile" set that to true and it all works. I just LOVE when stupid little problems consume 3 full days : )
-
Once again, thanks for looking at it with me Frinny!

5 1592
Frinavale
9,735 Expert Mod 8TB
Can't you just write the content to the response's output stream like you would in ASP.NET?

-Frinny
Oct 30 '14 #2
yarbrough40
320 100+
funny enough that didn't seem to work when I tried it but perhaps I wasn't doing it correctly - Thanks Frinny... I will revisit that path
Nov 1 '14 #3
yarbrough40
320 100+
no luck. I can't even figure out how to do it with a simple text file.. This little sample writes my file out to a directory. How would I write it out to the client for download?... man I feel like an idiot : )
Expand|Select|Wrap|Line Numbers
  1.      String data = "My Text To Put In The File";
  2.      byte[] byteData = data.getBytes();
  3.  
  4.      OutputStream out = new FileOutputStream("MyFile.txt");
  5.      out.write(byteData);
  6.      out.close();
Nov 2 '14 #4
Frinavale
9,735 Expert Mod 8TB
I'm not seeing you using response.out as the stream.

Do you have access to a response object?
Nov 3 '14 #5
yarbrough40
320 100+
I figured it out finally. I am using this within a Wavemaker project. Wavemaker has a bool property I did not see called "DownloadFile" set that to true and it all works. I just LOVE when stupid little problems consume 3 full days : )
-
Once again, thanks for looking at it with me Frinny!
Nov 5 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pedro Fonseca | last post by:
Greetings! In my PHP website I'm trying to raise a File Download dialog directly in a WindowsCE IE client with the following code: header( "Content-Type: application/octet-stream\n" );...
3
by: BOHICA | last post by:
I would like on my page when users click one of my mp3 files for the dialog box to pop up so they can choose to save the file to disk instead of trying to open through IE, but the dang thing won't...
3
by: Skwish | last post by:
Hi, I would like to download all the files from a folder (of various types i.e. ..txt, .dll, .dat, etc.). I tried Dim MyDir As IO.Directory Dim path As String = Me.MapPath(".") & "\Data" Dim...
19
by: Andrew Chalk | last post by:
How do I do file download from an ASP.NET v1.x page? Specifically if I have a link e.g. "Download" in a datagrid what code will cause the file download dialog to appear to the user? Many...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
6
by: Polaris | last post by:
Hi Experts: Is there an ASP.NET API to find a file on CLIENT machine? I'm using asp.net 2.0. Thanks in Advance! Polaris
1
by: ajaymohank | last post by:
Hello friends......... i am new to php. In my project i have to download a java page from a bat file, to the client side by passing values from the program. the problem is that i am getting the java...
4
by: Kaustubh Budukh | last post by:
I am designing a VB.NET based website I have a hyperlink, upon clicking on it a "File Download" prompt opens which asks me whether I want to "Save" the file, "Open" But I want it to...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.