Authentication uploaded by Java files

xiaoxiao2021-03-06  61

/ ** * Upload the implementation class uploaded, put the source file name After the time is stored as the name of the @Param Len Request * @Param ContentType Request * @Param in Request stream * @return Byte [] Upload file Byte array * / public byte [】 UPLOADTOBYTE (INT LEN, STRING ContentTy, InputStream in) {string Upfile = ";" Try {byte buffer [] = new byte [len]; int start = contenttype.indexof ("boundary = "); Int boundarylen = new string (" boundary = "). Length (); string boundary = contentType.substring (Start Boundarylen); boundary =" - " boundary; int total = 0; int Once = 0; While (Total = 0)) {ONCE = In. Read (Buffer, Total, Len); Total = ONCE;} String [] tokens = {"Name = /", "/ "; filename = /" "," / "/ r / n", "content-type:", "/ r / n / r / n"}; // POS0 record Boundary's first byte in Buffer Position INT POS0 = ByteIndexof (Buffer, Boundary, 0); INT POS1 = 0; // POS1 recorded in Buffer in the next position POS0 = boundarylen; // Record Boundary's next-byte subscript Pos1 = ByteIndexof (Buffer, Boundary, POS0); POS0 = 2 ; // Taking into account / r / n buffer = subndary (Buffer, POS0, POS1 - 2); int [] position = new int [tokens.length]; for (INT i = 0; i

Subbytestring (buffer, position [0] byteslen (tokens [0]), position [1]); // Get file name string filename = Subbytestring (buffer, position [1] byteslen (tokens [1]), Position [ 2]); System.out.Println ("FileName =" filename); //eg:11name="c:/set.sql "// Upload file path INT size = 0; for (int K = 0; K 0) // myfile = myfile.substring (a); // long LTIME = 0L; // Date DTime = New Date (); // LTime = DTIME.GETTIME (); // Get this identity // String Stime = LTIME ""; // converts this identity into a character object ///system.out. Println ("The file name is:" stime myfile); ///// String WritePath = "c: // logs //" STIME "_" myfile; // // String readpath = " C: // logs // " stime " _ " myfile; // string writepath = write_photo_path stime " _ " myfile; // String readpath = ied_photo_path stime

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

New Post(0)