|
-
February 3rd, 2013, 07:59 PM
#1
write to file in loop, help please--java
Can anyone help me please, I cant figure out what I am doing wrong or missing. I need to enter a sentence and write it to a file over and over again until the word done is typed then it should exit the program. please help
Code:
import java.util.*;
import java.io.*;
import java.lang.*;
public class StringtoFile {
public static void main(String[] args) throws IOException
{
StringtoFile h = new StringtoFile ();
h.openFile();
h.addline();
h.closefile();
}
private Scanner scan, X;
public void openFile(){
try{
X = new Scanner(new File("testFile.txt"));
}
catch(Exception e){
System.out.println("You received and Error");
}
}
public void addline(){
System.out.println("Enter a Sentence.....");
String str, casefinish = "done";
str = X.nextLine();
if(casefinish.equalsIgnoreCase("done")){
//break;
}
else{
while (str!="done");
str = X.nextLine();
}
}
public void closefile(){
X.close();
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|