import java.io.IOException;
import java.io.FileWriter;
import java.util.Scanner;
public class NewTxt {
public static void main(String[] args) throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("please enter ....(Quit-退出)");
String str;
FileWriter out = new FileWriter("d:\\test.txt");
do{
str = s.nextLine();
out.write(str+"\r\n");
}while(!"Quit".equalsIgnoreCase(str));
out.close();
}
}
读字符想楼上就可以了
写入文件个人认为改改:
File f = new File("e:\\jsText.txt");
boolean check = true;
if(f.exists()){
System.out.println("**********Exists File************");
}else{
try{
f.createNewFile();
System.out.println("**********Creat File************");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
if(check){
try{
//把数据保存到e:\jsTest.txt文件
FileWriter fw = new FileWriter("e:\\jsText.txt",true);
fw.write(s+"; \r\n");
fw.flush();
fw.close();
}catch(Exception e){System.out.println(e.getMessage());}
}
if(check){
try{
//把数据保存到e:\jsTest.txt文件
FileWriter fw = new FileWriter("e:\\jsText.txt",true);
fw.write(userNa + ";"+userAg +";"+userPa +";"+userEm +";"+userPh +";"+userSe +"; \r\n");
fw.flush();
fw.close();
System.out.println("*********-------Writer------*********");
}catch(Exception e){System.out.println(e.getMessage());}
}
}
%>