• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Viewing a CSV File

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this file path but I can not get it to display with the following code. See comments under CSV option:

 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The proper MIME type for CSV files is text/csv. It's then up to the browser to properly deal with it. That's apparently where it goes wrong.

If you save the CSV file instead, does it contain the right data? What happens if you open that saved CSV file by double clicking it?
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:The proper MIME type for CSV files is text/csv. It's then up to the browser to properly deal with it. That's apparently where it goes wrong.

If you save the CSV file instead, does it contain the right data? What happens if you open that saved CSV file by double clicking it?


http://simplyw/drawings/Openfiles/files.csv

If I use the text/csv and the open option the dialog appears asking what program to use. If I choose excel it opens with no data.

If I use the Save option the file saves okay but it is empty.

If I go to the actual file and double click it opens in excel.

If I use the path in browser window it also opens an excel file.

I have done one more thing. If I place the url in a link it works okay also. The above tries have been using the window.open(url) method.
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Dyke wrote:


There's a problem between those two lines of code. The second line expects the "filePath" variable to be a file path. The first line says it isn't one.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Steve Dyke wrote:


There's a problem between those two lines of code. The second line expects the "filePath" variable to be a file path. The first line says it isn't one.


This all works when the file type is a .pdf. I don't understand.
 
Paul Clapham
Sheriff
Pie
Posts: 20980
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then I think it's time to go back and look at what "can not get it to display" actually involves. Error messages? Something else displays? You know, the usual identification of the symptoms of the problem.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Then I think it's time to go back and look at what "can not get it to display" actually involves. Error messages? Something else displays? You know, the usual identification of the symptoms of the problem.


In my original post, within the code part of the csv option I gave comments as to what was happening. I have figured out as I mentioned a couple of posts ago if I bypass the window.open(url) method and just hard code a link to the url it works fine. By the way thanks for your help in this issue.
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul is right. You can only use FileInputStream with files on your local hard disk, and maybe on some shares (Windows shares, NFS).
To read files from a URL, you should use java.net.URL and its openStream() method to get an InputStream.

My guess is that if you check your log files you will see an exception printed to it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic