[Original] JSP read file (simple counter)

xiaoxiao2021-03-06  118

String filename = "//" new java.sql.date (system.currenttimemillis ()). TOSTRING () ". Txt";

String path = Request.getRealPath ("."); //Out.println (PATH); file f = new file (path, filename); //out.println (F); //out.println (F.exists ())

IF (F.Exists ()) {// Check if file.txt exists

} else {f.createNewFile (); // Create a file named file.println (Path FileName "in the current directory does not exist, established."); // Output current directory path }

PATH = Request.getRealPath (".");

INT count; // read a line data try {fileReader fr = new fileReader (Path filename); bufferedReader br = New BufferedReader (fr); // Establish a bufferedReader object, and instantiate BR String line = br.readline () Count = integer.valueof (line) .intValue (); br.close (); // Close BufferedReader object fr.close ();} catch (excEption e) {count = 0;}

COUNT ;;

FileWriter FW = New FileWriter (Path FileName); // Establish a FileWriter object, and instantiate FW // writes the string to file fw.write (string.valueof (count)); fw.close ();

Out.println (String.Valueof (count) "
");

转载请注明原文地址:https://www.9cbs.com/read-98998.html

New Post(0)