Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- IntelliJ
- MongoDB
- REACT
- subnetmask
- jenkins 설치
- 리액트
- jenkins jdk
- jenkins install
- java
- MySQL
- Docker
- grpc
- Linux
- jenkins github 연동
- spring
- jenkins github
- grafana
- error
- JavaScript
- jenkins maven
- 리눅스
- Jenkins
- Spring Boot
- vue.js
- docker network
- CI/CD
- gradle
- Jenkins Pipeline
- jpa
- nginx
Archives
- Today
- Total
뭐든 즐기면서 ;)
Java File Encoding / Java File 인코딩 본문
728x90
Library 추가하기
implementation 'com.googlecode.juniversalchardet:juniversalchardet:1.0.3'
소스 작성
import org.mozilla.universalchardet.UniversalDetector;
...
public static String getEncoding(MultipartFile file) {
String detectedCharset = null;
InputStream fis = null;
try {
byte[] buf = new byte[4096];
fis = file.getInputStream();
UniversalDetector detector = new UniversalDetector(null);
int nread;
while((nread = fis.read(buf)) > 0 && !detector.isDone()){
detector.handleData(buf, 0, nread);
}
detector.dataEnd();
detectedCharset = detector.getDetectedCharset();
if(detectedCharset != null && detector.isDone() && Charset.isSupported(detectedCharset)){
detector.reset();
return detectedCharset;
}
} catch (Exception e){
return "";
} finally {
try { if(fis != null) fis.close(); }catch (Exception e){}
}
return detectedCharset;
}
728x90
Comments