473,511 Members | 17,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to set the filedialog file "type" ... but nothing seems to do this...

blazedaces
284 Contributor
I've taken a look at the class and you only seem to be able to set the file name, but not it's save type.

Why is this?

Here's some code if you want it, but it doesn't seem to have a method for choosing the type of file to save:

Expand|Select|Wrap|Line Numbers
  1.     public void save(double[] x, double[] y) {
  2.         FileDialog fd = new FileDialog(new Frame(), "Choose a text file to save to...", FileDialog.SAVE);
  3.         fd.setFile("*.txt");
  4.         fd.setDirectory(".\\bodyFiles");
  5.         fd.setLocation(50, 50);
  6.         fd.setVisible(true);
  7.  
  8.         try {
  9.             out =  new PrintWriter(new FileOutputStream(fd.getDirectory() + System.getProperty("file.separator") + fd.getFile()));
  10.         }
  11.         catch (FileNotFoundException e) {
  12.             System.out.println("File not found exception: ");
  13.             e.printStackTrace();
  14.         }
  15.  
  16.         StringBuffer sb;
  17.         String ws = ",                                   ";
  18.         if (x.length != y.length) {
  19.             System.out.println("Both inputs to save should have the same number of points\nor the length of the arrays should be the same,\nbut they are not for some reason.");
  20.             System.exit(1);
  21.         }
  22.         for (int i = 0; i < x.length; i++) {
  23.             sb = new StringBuffer(60);
  24.             sb.append(i); sb.append(": "); sb.append(y[i]); sb.append(ws);
  25.             out.print(sb.substring(0, 30));
  26.             out.println(x[i]);
  27.         }
  28.         out.close();
  29.     }
  30.  
Anyone does this before, seems like there should be an obvious solution, sorry that I can't find it...

-blazed

Edit: Yes, if I type file'sName.txt for example it will save as type .txt, but not if I don't include the .txt at the end. I want the type to be set as txt and so I can type fileName in and it will save as a fileName.txt

Thanks again for your help and time...
Jun 13 '07 #1
3 2917
JosAH
11,448 Recognized Expert MVP
Does adding an appropriate FileFilter help you out?

kind regards,

Jos
Jun 13 '07 #2
blazedaces
284 Contributor
Does adding an appropriate FileFilter help you out?

kind regards,

Jos
I believe this is my answer, thank you very much. I just wish it was more simple...

Filefilter is an interface, so I have to make a class that extends it and then custom-make my own accept parameters...

Wish there was a way to just have a default fileFilter of filenameFilter (don't know the difference really) that I could say new fileFilter(".extension");

Note: I realize it's probably very easy to create this class yourself. I will, but I'm in a rush to finish a project with this today, so I'll get back to it.

Again, thank you very much Jos for your help...

-blazed
Jun 13 '07 #3
JosAH
11,448 Recognized Expert MVP
I believe this is my answer, thank you very much. I just wish it was more simple...

Filefilter is an interface, so I have to make a class that extends it and then custom-make my own accept parameters...

Wish there was a way to just have a default fileFilter of filenameFilter (don't know the difference really) that I could say new fileFilter(".extension");

Note: I realize it's probably very easy to create this class yourself. I will, but I'm in a rush to finish a project with this today, so I'll get back to it.

Again, thank you very much Jos for your help...

-blazed
You're welcome of course. Sun didn't pay attention when they designed their
FileFilter, i.e. they indeed forgot that there already existed a FileNameFilter.
Both do the same thing and indeed the implementations of such a Filter are
easy to build; in your accept method just do this:

Expand|Select|Wrap|Line Numbers
  1. return file.getCanonicalPath().endsWith(extension);
  2.  
... that's all there is to it.

kind regards,

Jos
Jun 13 '07 #4

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

Similar topics

2
44006
by: @lias | last post by:
Hi all I have a webpage where I want the user to input filenames. To make this easier, I use a file input type so that the user can select files rather than typing in the filename, using the...
1
27841
by: Jesper Hermansen | last post by:
Hi! I'm making a system that will generate Winamp-playlists. To make it easy for the user to add a file to the list, I'm using <input type="file">. The problem with this is that I only get...
9
13372
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript">...
12
4866
by: Charlie Zender | last post by:
Hi, I am unable to compile a large body of code with extremely pedantic compile time checks activate, so that warnings cause errors. With GCC 3.3.1, I do this with gcc -std=c99 -pedantic...
3
3150
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
3
2789
by: Wayne | last post by:
I downloaded the Office 2007 Beta today and have been clicking around Access and the other Office Apps. They all have clear type switched on despite the fact that I have it turned off in Windows. ...
4
7844
by: Petr Vileta | last post by:
Sorry if my question was be here earlier, I'm new here ;-) I have html form where is the tag <input id="x" type="file" name="upload"> and another fields. After submit script on server take some...
17
4542
by: haldie | last post by:
Well, a long time ago, some bright person got a hold of my computer and decided to "improve" it. Apparently they fouled up the default "open" option on the folder "file type," causing a folder to...
3
2991
by: BiGYaN | last post by:
I am not an expert in C, but from all the C code I've seen in my last 4yrs of coding in C, I observe that programmers only use only "FILE *" type and never the actual "FILE" type. So my question is...
8
1634
by: Oliver Graeser | last post by:
Hi All, I'm coming from Java to C++ and this is one of the very last problems I have so far... In Java, if I have, say, a class SISNode that extends NetworkNode, I can have a function that...
0
7245
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
7144
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...
0
7356
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
7427
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...
1
7085
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
7512
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...
0
5671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5069
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
449
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.