473,387 Members | 1,798 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,387 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 1591
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.