十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
怎么在java中接收ios文件?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供果洛州網(wǎng)站建設(shè)、果洛州做網(wǎng)站、果洛州網(wǎng)站設(shè)計(jì)、果洛州網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、果洛州企業(yè)網(wǎng)站模板建站服務(wù),10多年果洛州做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
1. 簡(jiǎn)單,只需理解基本的概念,就可以編寫適合于各種情況的應(yīng)用程序;2. 面向?qū)ο螅?. 分布性,Java是面向網(wǎng)絡(luò)的語言;4. 魯棒性,java提供自動(dòng)垃圾收集來進(jìn)行內(nèi)存管理,防止程序員在管理內(nèi)存時(shí)容易產(chǎn)生的錯(cuò)誤。;5. 安全性,用于網(wǎng)絡(luò)、分布環(huán)境下的Java必須防止病毒的入侵。6. 體系結(jié)構(gòu)中立,只要安裝了Java運(yùn)行時(shí)系統(tǒng),就可在任意處理器上運(yùn)行。7. 可移植性,Java可以方便地移植到網(wǎng)絡(luò)上的不同機(jī)器。8.解釋執(zhí)行,Java解釋器直接對(duì)Java字節(jié)碼進(jìn)行解釋執(zhí)行。
ios Multipart/form-data POST請(qǐng)求java后臺(tái)spring接口一直出錯(cuò),搞了兩天,終于解決了,積累下來
package com.xx.controller;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.nupaApp.model.FileMeta;
@Controller
@RequestMapping("/controller")
public class File1Controller {
LinkedList files = new LinkedList();
FileMeta fileMeta = null;
/***************************************************
* URL: /rest/controller/upload upload(): receives files
*
* @param request
* : MultipartHttpServletRequest auto passed
* @param response
* : HttpServletResponse auto passed
* @return LinkedList as json format
* @throws IOException
* @throws FileUploadException
****************************************************/
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ResponseBody
public String upload(HttpServletRequest request, HttpServletResponse response)
throws IOException, FileUploadException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);// 判斷是否是表單文件類型
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
List items = sfu.parseRequest(request);// 從request得到所有上傳域的列表
for (Iterator iter = items.iterator(); iter.hasNext();) {
FileItem fileitem = (FileItem) iter.next();
if (!fileitem.isFormField() && fileitem != null) {// 判讀不是普通表單域即是file
// 操作fileitem文件步驟,可以獲取大小、路徑
// 定義圖片輸出路徑
String imgPath = "e:" + System.currentTimeMillis() + ".jpg";
// 定義圖片流
InputStream fin = fileitem.getInputStream();
// 定義圖片輸出流
FileOutputStream fout = new FileOutputStream(imgPath);
// 寫文件
byte[] b = new byte[1024];
int length = 0;
while ((length = fin.read(b)) > 0) {
fout.write(b, 0, length);
}
// 關(guān)閉數(shù)據(jù)流
fin.close();
fout.close();
}
}
return "200";
}
} pom.xml 添加
commons-fileupload commons-fileupload 1.3.1 commons-io commons-io 2.4
spring-config.xml 添加bean
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。