473,486 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String Question

3 New Member
Hi,
I am writing a new file from information thats from another program.I can't figure out how to: write the input (String) that gets displayed in the JOptionPane to the file. So how would I do this would I call the String from the other class?
Mar 31 '10 #1
4 2115
jkmyoung
2,057 Recognized Expert Top Contributor
2 problems here:
1. Getting the String.
2. Displaying the String.
Which are you having problems with, and could you show the code you're using to try and do it?
Apr 1 '10 #2
sunshinegirl
3 New Member
Hi,
My problem would be getting the string from the GUI program I have already created. The string from program 1 has information that the user would input and would be printed out in a JOptionPane.

Like this:
Expand|Select|Wrap|Line Numbers
  1. string1 = "First Name" + first1.getText()+ "\nLast Name "+last1.getText()+ "\n Drivers License Number:" + dlabel1.getText()+ "\n Pick Up Date:" +pubox.getText()+ "\n Pick Up Time:"+ hours2.getSelectedItem()
  2.   + "\n Drop Off Date:"+ dobox.getText()+"\n Drop Off Time:" + hours.getSelectedItem()+"\n Car Type:"+ select.getSelectedItem()+ "\n Optional:"+ insurance.isSelected() + "\n Optional:"+gps.isSelected() +"\n Special Request:"+carea.getText()+"\n Payment Options:"+ card.isSelected()+card2.isSelected()+card3.isSelected()+card4.isSelected()+"\nCard Number:"+ cnbox.getText()+ "\nExpiration Date:" + edbox.getText();  
However I am trying to take this responses and write them to a new file using this:

Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class WriteToFileWithFormatter {
  5.  
  6. public static void main(String[]args) {
  7.  
  8.  File Brittney = new File("Brittney"); //Declaring & Initalizing 
  9.  //try  //{
  10.  //Scanner scn= new Scanner(rcfile);
  11.  //while(scn.hasNext()){
  12.  //String line = scn.nextLine();
  13.  //System.out.println(line);
  14. //} 
  15.   //}
  16.  //catch(FileNotFoundException fnfe) {
  17.  // System.out.println("Here is your Rental Information!!"); 
  18.   //}
  19.   Formatter output= new Formatter();
  20.    try{ 
  21.   output = new Formatter("C:\\Brittney.txt");  //writes a new file for you but you need to open it 
  22.   output.format( string1); 
  23.   output.close(); //have to close the program
  24.      }
  25.  
  26.  catch(FileNotFoundException fnfe){
  27.  output.close();  
  28.  System.out.println("File doesn't exist!!");   
  29.  } // local to this catch 
  30.  finally {
  31.   output.close();  
  32.  }
  33. }
  34. }
Apr 1 '10 #3
jkmyoung
2,057 Recognized Expert Top Contributor
Weird! It looks like it should work, although on my computer it doesn't unless I change the file location.
Check if you have permissions to create a new file at that location. By any chance are you running windows 7? Try creating the file in your user directory, eg, something like C:\\users\\bsmith\\documents\\test.txt
Apr 1 '10 #4
sunshinegirl
3 New Member
I have Vista actually but I rechecked the file location and that made it work. Except instead of typing the string1 I just tried the word hello and it worked.
Apr 2 '10 #5

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

Similar topics

2
1449
by: sparks | last post by:
I know this is a stupid question but I can't find the answer. Please tell me where to find reference to this so I can print it out and staple it to my head.. dim I as integer dim missedstr as...
5
3007
by: John Baro | last post by:
I have a richtextbox which I want the "literal" rtf of. richtextbox.rtf returns {\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\\uc1 }\r\n\0 when i put this into a string I get...
5
12441
by: Dave | last post by:
I'm receiving info from a com port into a string. I gradually process the string which constantly shortens it. The question is how long can a string be before I need to write some info to disk...
32
14760
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
2
8535
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the...
11
17618
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
53
4012
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
6
2191
by: tommaso.gastaldi | last post by:
Hi, does anybody know a speedy analog of IsNumeric() to check for strings/chars. I would like to check if an Object can be treated as a string before using a Cstr(), clearly avoiding the time...
39
2867
by: sucaba.r | last post by:
I don't know if this is a unique problem, or I'm going about it the wrong way. I currently connect to one of our SQL servers via a priviliged account (by using RUNAS). Works with no problem. I...
7
7794
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
7094
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
6964
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...
1
6839
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
7305
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
5427
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
4863
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
3066
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
259
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.