哈工大 java实验1 ATM系统的编写

File userFile = new File("UserInfo.txt");                               
FileWriter fw = null;
fw = new FileWriter("UserInfo.txt");                                  //这样写会覆盖之前的内容
for (int i = 0; i < userList.size(); i++) {
    fw.write("abc"+ "\r\n");                                                   //     /r/n 为回车  只有/n的话 会显示一个黑框很难看 /r 是把光标移回首行
    fw.flush();                                                                       //所写的数据可能先写入缓存,有可能不写入文件,flush()一下为了保险。
 }
 fw.close();                                                                       //不要忘了关闭流

//================================================================================================================================

File userFile = new File("UserInfo.txt"); 

BufferedReader reader = new BufferedReader(new FileReader(userFile));                 
   while ((userLine = reader.readLine()) != null) {
    String[] ss = new String[10];
    ss = userLine.split("#");                                                                                               //split这个东西对格式化处理特别有用,c++里好像就没有
    System.out.println(ss[0] + ss[1] + ss[2] + ss[3] + ss[4]);
   }

//================================================================================================================================

StringA.equals(StringB)             //这是对的,没有c++方便。。。

StringA==StringB                       //这是不对的,java里string是个类,这样比较是比较类指针(java里没指针- -!,那就是内存地址把),只有变量是同一个是才为真。

//==================================================================================================================================

BufferedReader br = new BufferedReader( new InputStreamReader(System.in));   //inputStreamReader本身有read方法,不过听说效率很低,用BufferedReader包装一下,效率会高,它是支持缓存啥的。

String num = br.readLine();                                                                      //读数据的话比较简单

你可能感兴趣的:(java,c,String,File,null)