Writing to file not working, might be 1.4 problem
Hi:
I am trying to writing the content of a JTextArea onto a file. The content is pretty big, has newlines. I have been struggling with this in 1.4 and it just doesn't write to the file I specified. In 1.3, it works great. Here is the rough code:
public void loadDisplayFrame()
JMenuItem save = new JMenuItem("Save");
//Save Action Listener
save.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent ae)
String filePath;
//Save the gsgl sample file
if(filePath!=null && filePath.length()>0)
try
int state = saveChooser.showSaveDialog(null);
File f;
f = saveChooser.getSelectedFile();
if(f!=null && state==JFileChooser.APPROVE_OPTION)
savedName = f.getPath();
if(!savedName.endsWith(".gsgl"))
JOptionPane.showMessageDialog(null, "Invalid file name", "error", JOptionPane.ERROR_MESSAGE);
}else
processSaving();
}catch(Exception e)
e.printStackTrace();
}else
JOptionPane.showMessageDialog(null, "Please load a file first", "error",
JOptionPane.ERROR_MESSAGE);
myMenu.add(save);
JMenuBar displayMenu = new JMenuBar();
displayMenu.add(myMenu);
public void processSaving()
try
System.out.println("Saved Name is " + savedName);
PrintWriter out
= new PrintWriter(new BufferedWriter(new FileWriter(savedName)));
//name of TextArea is <display>
String saveCode = display.getText();
System.out.println(saveCode);
out.print(saveCode);
out.close();
}catch(Exception e)
System.out.println("Exception in writing" + e.toString());
Anyone knows what is going on? I am hoping to use 1.4 for my project. But this thing is not working. Any way around it? Thanx
Try putting in this line before your close:
out.flush();
PrintWriter buffers the data and won't send it until you exit or enough data gets into the buffer to cause a flush. I assume that you are getting a zero byte file. You can also construct a PrintWriter with a boolean to indicate if it should auto flush the buffer.
Hope that it helps.
Paul
Similar Messages
-
Ive used compressor and then tried to put it in dvdsp put its not working. I am having problems with the audio or when i burn it , i cant play the dvd? any help would be appreciated
I suspect you are attempting to burn an HD DVD, which will not play on a DVD player...
But if you provide more details such as the settings you are applying in Compressor, then we would be able to provide you more accurate information.
How are you adding the files to Compressor?
In FCP, what are your footage properties (command-9) and sequence settings (command-0) -
signed up twice for adobe pdf export to word and still not working - anyone else have this problem?
In XI.
I can’t just export to word as I have done in the past in one simple click.
Convert to button is greyed out.
Now I have to save the pdf file on c drive when I am in outlook…then goto export pdf file…then find file then export to word.
I bought new computer with windows 8 (which is awful) and then bought pdf export again…
Any thoughts on how I can get back to one simple click again when I open a pdf file from an email in outlook?
Thank you,
Mike -
There is a problem with my apple watch.it is not working well .There is a problem in its charging .The repairers says that contact to your company and ask them to provide you its software.
Please help me.Please be aware that you are not communicating with Apple when you post in these forums. These are user-to-user support forums, so in almost all cases the only people who will reply to your posts are, like me, your fellow users.
As to your issue, Apple does not and never has made a wristwatch as such. The only thing close to a watch that they have made was the 6th-generation iPod nano:
http://support.apple.com/kb/ht1353#iPod_Nano_6G
which has a clock feature and which some people have worn as a wristwatch. Is that what you mean?
Message was edited by: varjak paw -
my phone doesn't ring when someone is calling, but the sound works otherwise, like the alarm etc. I have tried to fix it in settings but still not working. anyone else have this problem?
Thanks so much but none of that helped. It was driving me crazy because it would back up another external drive. I just changed the name of the drive from iPhoto/iTunes Library to Media Libraries and IT WORKED!! I guess for some reason it didn't like the drive being called iPhoto or iTunes ???? I don't understand but I have tried so many solutions and exchanging things out but the name change did it????!!!
Thank you for your help and replying to this. Guess I made my own issue! -
Microsoft Office 2011 no longer opens because "there is a problem" after updating mountain lion when the app store said there was an update available this morning. Reinstalling did not work. What's the problem?
Has your problem been solved by the updates??
Have a similar problem. This MacBook opened all MS Office programs in Dec2012 but no longer does in Feb2013. Went to Microsoft/mac/downloads but none of the three updates would run citing a problem "version of software needed to run this update was not found on this volume".
MacBook: 7.1, Intel Core 2 Duo, 2.4 GHz
Microsoft Office 2011: version 14.2.3
Mountain Lion: 10.8.2 (12C60) -
i'm having to double click everything & the slide feature is not working. What's the problem? Resetting fixes it for a couple seconds then it goes right back.
i.e. If I go to open my mailbox, i have to 1st select the icon. then double tap it to open. same thing once I get to an email.At a guess, turn off VoiceOver: Settings > General > Accessibility > VoiceOver. Use three fingers to scroll.
-
i am using firefox 3.6.17 i upgraded it to 4.1.but it does not work properly sometimes it opens every website and most of the time it does not work . so what is the problem please help . thank you
Did you check your security software (firewall)?
A possible cause is security software (firewall) that blocks or restricts Firefox or the plugin-container process without informing you, possibly after detecting changes (update) to the Firefox program.
Remove all rules for Firefox from the permissions list in the firewall and let your firewall ask again for permission to get full unrestricted access to internet for Firefox and the plugin-container process.
See:
* [[Server not found]]
* [[Firewalls]] -
Personal hotspot missing and music volume not working and lots of other problem after updated 4s to ios8 ? Apple disappointed this time badly.
GO to Setting > Cellar Data > VPN Settings > Add any user and password under Personal Hotspot, then you will see it's activated again as usual
-
Trying to get a refund on an app that do not work, but the report a problem button is grey out
Hi
I'm trying to get a refund on an app that do not work, but the report a problem button is gray out & Apple wants £20.00 for support
where do I go from here
ThanksTo report a problem less than 90 days:
http://reportaproblem.apple.com
Sign in with the AppleID and Password used for the purchase.
How to report an issue with your iTunes Store, App Store, Mac App Store, or iBooks Store purchase
http://support.apple.com/kb/HT1933
To report a problem greater than 90 days:
http://www.apple.com/support/itunes/store -
I have a 2010 mac book pro and track pad is not working well, is there a problem with that year. I heard that the 2011's had track pad trouble.
All recent versions of Mac OS X use bash, so avoiding Mavericks won't help you with that problem (which isn't a problem for most users).
iWeb is another matter. My advise: migrate your website to Wordpress first and start thinking about upgrades later. -
Hi my name is Vajra from INDIA, i am using ipod shuffle 3rd generation but it is not working properly due to battery problem, i need to change the battery please guide me how to change the battery or any chance to replace the ipod shuffle 3rd generation ?
Seems no one care about us .no one replied till no@!!!!@ strange
-
My sleep/wake button is now not working and than I faced problems with my sound, now my iphone speakers aren't working? What shall I do?
The problem isn't solved after the restore, shall I bring my phone to the AppStore? Will they give me a new one? Or I should pay for that. Warranty is until December 2013;)
-
last update to ios6 - worst ever, facetime does not work as it used to, problems with skype, losing connection or no9t connecting facetime to face time. Do something with it.
I'm not sure yet, but It may be as simple as "settings", "FaceTime" "Off"
-
Calendar Alarm Open FIle not working in Mountain Lion
Recently upgraded my mac mini server to 10.8.2 Mountain Lion. I need it to open a particular Filemaker file every morning, and close the application every night. Used to have a simple alarm in iCal set to do this with Open File and then a very simple Automator script to close the program at a scheduled time, also in iCal. Worked fine. Now, in trying to recreate this, it doesn't work - I make the scripts, and if I set them for a time I can test them (ie. 5 minutes from now), they work as planned, but they will not function on their own at the scheduled time. I thought it might be going to sleep, so I set Energy Saver to Never go to sleep, unchecked "Put hard disks to sleep when possible", and checked "Wake for network access". Still not working. Any thoughts? Any idea how to even troubleshoot this?
I thought I was on to something, but then I re-read your post and saw that you've successfully tested your scripts in Calendar. So, all I've got left to offer is a silly question: has the calendar been set to ignore alerts? I ask because just within the last few days I created an Automator calendar alarm, tested it successfully (in the same fashion as you), and set it off to run on its merrily-scheduled way, only to discover it wasn't firing on its own. Like you, I double-checked my Energy Saver settings and it looked like things should work just fine. What I finally found was that at some point during all my testing and fiddling I'd ticked the "Ignore alerts" box for the calendar, and that's what was keeping my script from firing.
Maybe you are looking for
-
Installation problem with already installed apache, help!
Alright, I have oracle 9i client installed on a windows 2000 machine. I'm admin (it is a laptop that dual boots Solaris and Windows 2000). I also had apache 2 and tomcat with jk2 connector. Normally I run a web app off of this laptop, connecting to a
-
Getting to data stored in time machine hard drive
I was running time machine on my macbook pro, and tonight the logic board of the MBP died on me. There are several files I need ASAP on the (external usb) time machine drive. If I plug the drive to another mac (mac pro I have at work), is it possible
-
Want to make Monday as the first day of the week in GregorianCalendar. how?
hi I need to know what day is the first of the month is. for example the 1st of Nov 2004 is Moday and 1st of Dec 2004 is saturday. I am using the GregorianCalendar: 1. GregorianCalendar calendar = new GregorianCalendar(2004,11,1); //set date to 1
-
Populating a collection with function results
I am calculating some statistics and need to use a collection to store the results of several function so they can be used in a procedure. Example: PROCEDURE PRODUCTIVITY_INSERT(p_first_of_month IN DATE) AS BEGIN vc_FirstofMonth := p_first_of_month;
-
How to change the log file path in BEA tuxedo 6.5 client in Windows xp
Hi, I am using BEA Tuxedo 6.5 client in windows xp. The log files are created in C: Kindly help me in changing the log file path and also i want to know where these configurations are set. Advance thanks !!! Regards Bunsim