Java file operations Daquan 1: the establishment of documents, checks and delete

  Abstract: Java file operations Daquan 1: the establishment of documents, checks and delete 

  </ Td> </ tr> <tr> <td width="443" height="35" valign="top" class="ArticleTeitle"> <% @ page contentType = "text / html; gb2312 charset ="% > 
  <% @ Page import = "java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); 

  Out.println (path + " 
");
  File f = new File (path, "File.txt"); 
  Out.println (f + " 
");
  / / Out.println (f.exists ()); 

  If (f.exists ()){// check whether there File.txt 
  F.delete ();// delete documents File.txt 
  Out.println (path + "\ \ File.txt exist, has been deleted."); 
  Else () 
  F.createNewFile ();// under the current directory creation of a document entitled File.txt 
  Out.println (path + "\ \ File.txt did not exist, the current output has been established 。");// the directory path 
  ) 
%>
  </ Td> <td width="264" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

Java file operations Daquan 4: read the paper

  Abstract: Java file operations Daquan 4: read the paper 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <% @ page contentType = "text / html; gb2312 charset ="%> 
  <% @ Page import = "java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); / / Get the current directory path 
  FileReader fr = new FileReader (path + "ReadData.txt ");// establish FileReader object, and examples into fr 
  BufferedReader br = new BufferedReader (fr); / / build BufferedReader object, and examples into br 
  String Line = br.readLine ();// his string read from the document 
  / / Reader to judge whether the string is empty 
  While (Line! = Null) ( 
  Out.println (Line + " 
  ");// Read from the paper output data 
  Line = br.readLine ();// continue to read from the document in his data 
  ) 
  Br.close ();// closed BufferedReader target 
  Fr.close ();// closing documents 
%>
  </ Body> 

  <table Width="730" border="0"> <tr> <td width="724"> </ td> </ tr> </ table> </ td> </ tr> <tr> 

  ↑ Back 

Java file operations Daquan 2: directory establishment of checks and delete

  Abstract: Java file operations Daquan 2: Contents of the establishment of checks and delete 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="729" border="0"> <tr> <td width = " 723 "> </ td> </ tr> </ table> 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
  <% @ Page import = "java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); 
  Path = path + "\ \ Sub" / / will be established by the directory path 
  File d = new File (path); / / Sub directory that represents the File object, and a quote to get it 
  If (Sub d.exists ()){// check whether there directory 
  D.delete (); 
  Out.println ( "Sub directory exists, has been deleted"); 
  Else () 
  D.mkdir ();// establish Sub directory 
  Out.println ( "Sub directory does not exist, has been established"); 
  ) 
%>
  </ Body> 
  </ Td> </ tr> <tr> 

  ↑ Back 

Properties file for use with mysql database connection pool proxool

  Abstract: The paper attributes assigned to mysql database connection pool proxool 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> 
  1, to write a document attributes: Proxool.properties, Add to your application's WEB WEB-INF \ classes below, as follows: 
  Jdbc-0.proxool.alias = mysql 
  Jdbc-0.proxool.driver-class = org.gjt.mm.mysql.Driver 
  Jdbc-0.proxool.driver-url = jdbc: mysql: / / localhost: 3306/soft? User = root & password = 

  <table Width="673" border="0"> <tr> <td width="387"> 
  Jdbc-0.proxool.maximum-connection-count = 20 
  Jdbc-0.proxool.prototype-count = 4 

  Jdbc-0.proxool.house-keeping-test-sql = select CURRENT_DATE 
  Jdbc-0.proxool.verbose = true 
  Jdbc-0.proxool.statistics = 10s, 1m, 1d 
  Jdbc-0.proxool.statistics-log-level = DEBUG 

  2, so write web.xml: 
  <? Xml version = "1.0" encoding = "ISO-8859-1"> 

  Web-app 
  PUBLIC "- / / Sun Microsystems, Inc / / DTD Web Application 2.3 / / EN" 
  "Http://java.sun.com/dtd/web-app_2_3.dtd"> 

  </ Td> <td width="276"> </ td> </ tr> </ table> 


ServletConfigurator
  Org.logicalcobwebs.proxool.configuration.ServletConfigurator 


  PropertyFile 

WEB-INF/classes/Proxool.properties

  A 



Admin
  Org.logicalcobwebs.proxool.admin.servlet.AdminServlet 



Admin
  / Admin 




  3, will be the driving procedures mm.mysql-2.0.14-bin.jar and proxool-0.8.3.jar Add WEB-INF \ lib directory. 
  4, Below is the test jsp documents: 
  <% @ Page import = "java.sql .*"%> 
  <% @ Page contentType = "text / html; charset = GB2312"%> 


<head>

  </ Head> 
<body>


  Use Proxool Connection Pool 



<%
  Connection con = null; 
  Statement stmt = null; 
  ResultSet rs = null; 
  Try ( 
  Con = DriverManager.getConnection ( "proxool.mysql"); 
  Stmt = con.createStatement (); 
  String query = "select * from count_num"; 
  Rs = stmt.executeQuery (query); 
  While (rs.next ()) ( 
  Out.print (rs.getLong (1 )+"– OK "); 
  ) 

  Stmt.close (); 
  Con.close (); 
  ) Catch (SQLException sqle) ( 
  Out.println ( "sqle =" + sqle); 
  ) 
  Finally ( 
  Try ( 
  If (con! = Null) ( 
  Con.close (); 
  ) 
  ) Catch (SQLException sqle) ( 
  Out.println ( "sqle =" + sqle); 
  ) 
  ) 

%>

  </ Body> 


  5, statistics and background information 

  Please go to: http://127.0.0.1:8080/testpxool/Admin 
  (Testpxool should read your application WEB) </ td> </ tr> <tr> 

  ↑ Back 

Java file operations Daquan 6: Skip bytes do not read

  Abstract: Java file operations Daquan 6: Skip bytes do not read 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="730" border="0"> <tr> <td width = " 724 "> </ td> </ tr> </ table> 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
  <% @ Page import = "java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); 
  FileReader fr = new FileReader (new File (path, "ReadData.txt "));// establish FileReader object, and examples into fr 
  Out.println ( "the current directory:" + path + " 
");
  Fr.skip (2); / / Skip two bytes 
  Out.println ( "read out the contents of the documents:" + " 
");
  Int c = 1 byte read fr.read ();// 
  While (c! =- 1) ( 
  Out.print ((char) c); 
  C = fr.read (); 
  ) 
  Fr.close (); 

%>
  </ Body> 


  Attachment: ReadData.txt: 

ASFFFAF
  3234242 </ td> </ tr> <tr> 

  ↑ Back 

Java file operations Daquan 5: directory listed in the document

  Abstract: Java file operations Daquan 5: directory listed in the document 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="734" border="0"> <tr> <td width = " 728 "> </ td> </ tr> </ table> 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
  <% @ Page import = "java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); 
  File d = new File (path); / / set up the current directory in the File object files 
  File list [] = d.listFiles ();// made on behalf of all the files in the directory object array File 
  Out.println ( "" + path + "directory paper: 
");
  For (int i = 0; i    If (list [i]. IsFile ()) ( 
  Out.println (list [i]. GetName () + " 
");
  ) 
  ) 
  Out.println ( " 
  "+ Path +" directory under the directory: 
");
  For (int i = 0; i    If (list [i]. IsDirectory ()) ( 
  Out.println (list [i]. GetName () + " 
");
  ) 
  ) 
%>
  </ Body> 

  </ Td> </ tr> <tr> 

  ↑ Back 

Java file operations Daquan 3: attributes of a document

  Abstract: Java file operations Daquan 3: attributes of a document 

  </ Td> </ tr> <tr> <td width="513" height="35" valign="top" class="ArticleTeitle"> <% @ page contentType = "text / html; gb2312 charset ="% > 
  <% @ Page import = "java.util.Date, java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); 
  File f = new File (path, "ReadData.txt"); 
  If (f.exists ()) ( 
%>
  <% = F.getName ()%> attributes are as follows: 


  Document length: <% = f.length ()%> 
  <% = F.isFile ()? "Document": "No documents"%> 

  <% = F.isDirectory ()? "Directory": "not a directory"%> 

  <% = F.canRead ()? "Can be read": "Do not read"%> 

  <% = F.canWrite ()? "Write": "Do not write"%> 

  <% = F.isHidden ()? "Hidden files": "no hidden files"%> 

  The document was last modified date: <% = new Date (f.lastModified ())%> 

<%
  Else () 
  F.createNewFile ();// under the current directory creation of a document entitled ReaData.txt 
%>
  <% = F.getName ()%> attributes are as follows: 


  Document length: <% = f.length ()%> 
  % = F.isFile ()? "Document": "No documents"%> 

  <% = F.isDirectory ()? "Directory": "not a directory"%> 

  <% = F.canRead ()? "Can be read": "Do not read"%> 

  <% = F.canWrite ()? "Write": "Do not write"%> 

  <% = F.isHidden ()? "Hidden files": "no hidden files"%> 

  The document was last modified date: <% = new Date (f.lastModified ())%> 

<%
  ) 
%>
  </ Body> 
  </ Td> <td width="171" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

Java file operations Daquan 8: how to write additional data to a file

  Abstract: Java file operations Daquan 8: how to write additional data to a file 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="731" border="0"> <tr> <td width = " 725 "> </ td> </ tr> </ table> 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
  <% @ Page import = "java.io. *"%> 

<head>

  </ Head> 
<body>
<%
  String path = request.getRealPath ( "/ article/article5a/example/filetest"); 
  RandomAccessFile rf = new RandomAccessFile (path + "\ \ WriteData.txt", "rw"); 
  / / Define a category RandomAccessFile targets, and examples of 
  Rf.seek (rf.length ());// mobile pointer at the end of the document 
  Rf.writeBytes ( "\ nAppend a line to the file!"); 
  Rf.close ();// close the document flow 
  Out.println ( "writes the document says: 
");
  FileReader fr = new FileReader (path + "\ \ WriteData.txt"); 
  BufferedReader br = new BufferedReader (fr); / / read the document object BufferedRead 
  String Line = br.readLine (); 
  While (Line! = Null) ( 
  Out.println (Line + " 
");
  Line = br.readLine (); 
  ) 
  Fr.close ();// closing documents 
%>
  </ Body> 
  </ Td> </ tr> <tr> 

  ↑ Back 

File upload Principle

  Abstract: file upload Principle 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> <table width="664" border="0"> <tr> <td width = " 380 "> We know that the use of uploading files similar to the following form to file selection: 
  Upload.html 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 

  <body Bgcolor="white"> 
  <form Action="doUpload.jsp" method="post" enctype="multipart/form-data"> 
<table>
  <tr Align="center"> 
  <td Width="55%" align="left"> <input type="file" name="text1"> </ td> 
  </ Tr> 
  <tr Align="center"> 
  <td Width="55%" align="left"> <input type="file" name="text2"> </ td> 
  </ Tr> 
  <tr Align="center"> 
  <td Colspan="2"> <input type="submit" value="上传"> </ td> 
  </ Tr> 
  </ Table> </ form> </ body>    </ Td> <td width="274"> </ td> </ tr> </ table> 
  Form used enctype = "multipart / form-data" to identify the forms can file upload operation. 
  Then when we choose two small 1. Txt and 1. Zip and click the submit button, the form processing doUpload.jsp jsp pages can be received from the upload.html-what information? 
  Take a look: doUpload.jsp it obtained from the request object input flow, and will request the content branch output. 
  <% @ Page contentType = "text / html; gb2312 charset ="%> 
<%
  Int size = 0; 
  Byte readByte [] = new byte [4096]; 
  Int j = 1; 
  ServletInputStream servletInputStream = request.getInputStream (); 
  While ((size = servletInputStream.readLine (readByte, 0, readByte.length ))!=- 1) ( 
  String line = new String (readByte, 0, size); 
  Out.println ("("+ j + ")" + + line " 
");
  J + +; 

  ) 
%>

  After the implementation of the above documents will be produced the following results: (choice of different upload files, similar results) 
  (1) ———————————————– 7d45a76025c 
  (2) Content-Disposition: form-data; name = "text1" filename = "C: \ Documents and Settings \ cwb \ Desktop \ 1. Txt" 
  (3) Content-Type: text / plain 
(4)
  (5) public static void main (String [] args) ( 
  (6) FileUtil.makeDir ( "dir1/dir2/dir3/dir4", "c: / java /"); 
  (7)) 
  (8)) 
  (9) ———————————————– 7d45a76025c 
  (10) Content-Disposition: form-data; name = "text2" filename = "C: \ Documents and Settings \ cwb \ Desktop \ 1. Zip" 
  (11) Content-Type: application / x-zip-compressed 
(12)
  (13) PK &? 1 
  (14) 6ex 1.txtSP ((M LV macrophages (I, Re?) 
  (15)??% E? Qing? 
  (16)? Fig? 
  (17) accounted for \ 
  (18)? Basic guarantee Z ?????? Yd? $? 1? 0Q? Against J?, K? Ye - T - U PK & counselled? 1 
  (19) 6ex? 1.txtPK 3? 
  (20) ———————————————– 7d45a76025c – 

  Here (1) (9) (20) is the boundary line.    From paragraph (2) line with paragraph (10) to upload files in the full name and other information.    (4) and (12) is empty row, followed by air after the upload the contents of the documents.    So, you should understand how to write components upload!    Extraction empty row after the contents of the documents, it will write FileOutputStream.    (See ntsky upload source components). 
  </ Td> </ tr> <tr> 

  ↑ Back 

Another tomcat web application under the build.xml file

  Abstract: another tomcat web application under the build.xml file 

  </ Td> </ tr> <tr> <td width="513" height="35" valign="top" class="ArticleTeitle"> <? Xml version = "1.0"> 

  Build file for the JCatalog Project. 

  Derek Y. Shen 
  6 / 2004 























  Description = "Create build directories."> 















  Description = "Compile Java files and copy static files."> 













































  </ Td> <td width="171" valign="top" class="ArticleTeitle"> 
  </ Td> </ tr> <tr> <td height="25" colspan="2" valign="top" class="ArticleTeitle"> 

  ↑ Back 

keep looking »