other.jsp
<%@ Page Language="Java"Import="java.util.*"pageencoding="UTF-8"%><% StringPath=Request.getcontextpath (); StringBasePath=Request.getscheme ()+ "://" +Request.getservername ()+ ":" +Request.getserverport ()+Path+ "/";%><%@page Import="java.io.*" %><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTML><Head><Basehref= "<%=basePath%>"><title>My JSP ' other.jsp ' starting page</title></Head><Body> <%
file File=new file ("C://users//x550v//desktop", "Cc.txt");intN=-1; //defines the length of the byte array, and 100 indicates that you can use the a[0]~a[ About] bytea[]=New byte[Ten]; InputStream in=Newfileinputstream (file); //intRead ()//reads a single byte of data from the source of the output stream, with a return value of 0~255, if empty, returns-1 // while((n=in.read ())!=-1){ //here n can not be replaced with in.read (), if replaced, equivalent to the second call to the method, from 2,4, 6 double bytes start reading//out.print (n+"<br>"); //} //intRead (byteb[])//from the source of the input stream, in, reads a length of a.length bytes to the byte array A, returns the number of bytes actually read, or, if the end of the file, returns-1 //In.read (a); for(intI=0; I<A.length;i++){ //if the contents of Cc.txt are B, then A[i] is the ASCII code corresponding to B.//out.print (A[i]+"<br>"); //Out.print (a.length); } try{//intRead (byte[] B,intoff,int Len), returns the number of bytes actually read, or, if the end of the file, returns-1 //B: Byte array, off: Starts reading from the first byte in byte array B,Len: Indicates read every two bytes while((n=In.read (A,0, 2))!=-1){ Strings=New String(A,0, N); Out.print (S+"<br>"); } in.close (); } catch (IOException e) {out.print (e); } </Body></HTML>
MyEclipse------Quickly read the contents of a file in a specific directory