473,670 Members | 2,397 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 2923
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(".ex tension");

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(".ex tension");

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
44017
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 HTML below. <input type="file" size="25" maxlength="256" id="filename" onchange="AddFile()" /> The problem I have is that the javascript function AddFile() is only run under
1
27876
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 the filename, not the path, which is necessary in my situation. I cracked the problem in Firefox:
9
13397
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"> However, I have found that I can use an alternate file extension, such as <script src="foo.HTML" type="text/javascript"> It works fine with my IE 6 and Mozilla. Will it work with other browsers?
12
4877
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 -Wall -Wunused -Werror -W -Wmissing-prototypes -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -c -o foo.o foo.c
3
3161
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 I find a list of all the types which can be returned? For example, if it is a Word document will it return "document/doc".
3
2806
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. I couldn't see anywhere to turn it off (maybe I missed it) - hopefully the finished product will have this option. Do other users use clear type? I find that my LCD display is razor sharp with it turned off and all fonts are decidedly blurry...
4
7856
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 validation on some fields and if te error is found the same form is generated with error reporting message. But the content of the "file" input is lost. I test it in IE6 and parameter value="???" not work here. I try to put string into input...
17
4556
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 open in a new window -regardless- of what you have your options set to. So, before I go digging around in the registry, I want to hear what you all would suggest doing to fix it. All these new windows are driving me nutters. Oh, before I forget:...
3
3001
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 : <1what is the actual use of this structure; i.e. can it be used anywhere in general programming? It is of course a very important structure, but can we make use of it a standard C program? I am told that using internals of this structure is...
8
1639
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 returns a NetworkNode but I can assure the compiler that it is in fact a SISNode and therefore call the method getStatus() that only a SISNode has. Like SISnode s,t; NetworkNode n;
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8661
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7419
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6213
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2800
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.