473,388 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

String Question

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

✓ answered by jkmyoung

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

4 2113
jkmyoung
2,057 Expert 2GB
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
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 Expert 2GB
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
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...

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.