| Author | Message | 
		 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 5:50 pm    Post subject: Help with converting information from file to variable |  |   
				| 
 |  
				| I am trying to make it so that i can read a file and make certain lines into variable info Say for example in the file i was reading, line 1 had the number 100 written on it
 how would i make it so that an int variable will be equal to that 100?
 
 I am also having another problem
 when i use this code
 
 String text = "Hello\n"
 String text2 =  "What is your name?"
 File file = new File("receipt.txt");
 output = new BufferedWriter(new FileWriter(file));
 output.write(text);
 output.write(text2);
 output.close();
 
 it works fine it will print the text variable into a file but when i try to go to next line say by using \n
 it will not, instead it will just continue to write in one big line and put a [] box whereever \n was.
 
 Any help is appreciated
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
		 
		| Sponsor Sponsor
 
  
   |  | 
	 
		|  | 
				 
		| andrew. 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 5:53 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| I'm just taking a guess here, but doesn't Windows have different line endings than other OSes? Like it's supposed to be something like "\r\n". |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 5:55 pm    Post subject: Re: Help with converting information from file to variable |  |   
				| 
 |  
				| hmm. Ill try that. yeah im using windows Xp. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 5:57 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| uhh it didnt work. It got rid of the box, but it still not printing onto the next line. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Euphoracle 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 7:42 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| don't use \n, use the os's line terminator (this can be accessed by using writeln instead of write) |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 7:50 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| oh so its kinda of like System.out.println and
 System.out.print
 
 K thnx
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 8:04 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| it doesnt let me compile it says somthingis wrong with the writeln command
 Error message:
 
 K:\IrfanISUinput.java:20: cannot find symbol
 symbol  : method writeln(java.lang.String)
 location: class java.io.Writer
 output.writeln(text);
 ^
 1 error
 Finished
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Euphoracle 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 8:17 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| oh I saw 'File' and 'Writer' below it and thought you were using a FileWriter.  for a BufferedWriter, just do your .write without a \n, then follow it by a newLine() 
 this:
 
 output.write("fish");
 output.newLine();
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
		 
		| Sponsor Sponsor
 
  
   |  | 
	 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 8:39 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| when i use that i get this error K:\IrfanISUinput.java:22: cannot find symbol
 symbol  : method newLine()
 location: class java.io.Writer
 output.newLine();
 ^
 1 error
 Finished
 
 Just a note - Im using Public class in Jpad Pro 6.5
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Barbarrosa 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 9:22 pm    Post subject: Re: Help with converting information from file to variable |  |   
				| 
 |  
				| You've initialized "output" as a Writer, not a BufferedWriter. The Writer class does not have newLine(), thus denying you access to this useful method. You should either change the type it's initialized with or cast it to a BufferedWriter when calling the method. 
 
 	  | Java: |  	  | 
((BufferedWriter)output).newLine();
 
 | 
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Euphoracle 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 9:37 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| Or rather than casting it, you can correctly create a BufferedWriter.  Sorry you misinterpreted my previous post, it could have been better worded. |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 9:54 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| Thanx guys its working now. Unfortunately this only solves my second problem. The first is the one that has me bamboozled. I have no idea. Basically our teacher doesnt want us writing prices in our program. She wants it to be in a seperate file so that it can be changed by someone who doesnt know java
 But i dunno how to take my read info and make a variable = to the read information.
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| Euphoracle 
 
  
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 10:38 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| Care to elaborate?  What are you using to 'read info'? |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 10:52 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| This is my code for reading my file: 
 FileInputStream Pizzastream = new FileInputStream("PizzaCostInformation.txt");
 DataInputStream Bread = new DataInputStream(Pizzastream);
 BufferedReader Cheese = new BufferedReader(new InputStreamReader(Bread));
 
 This is the file its reading:
 
 Medium Pizza
 9.25
 Large Pizza
 10.95
 Extra-Large Pizza
 13.50
 Regular Topping
 1.50
 Gourmet Topping
 1.95
 Dipping Sauce
 0.69
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		| illzidaneyou 
 
 
 
 
 | 
			
				|  Posted: Sun Jan 10, 2010 10:53 pm    Post subject: RE:Help with converting information from file to variable |  |   
				| 
 |  
				| So like how could I make a variable that is like double Pizza = Line2 which is 9.25?
 Is there a way to do that or am i approaching this the wrong way.
 Cuz all my teacher said was that all the prices had to be loaded from a file.
 |  
				|  |  | 
	 
		|  |  | 
	
 
		|  | 
				 
		|  |