public void replace(StringBuilder builder, String from, String to)

{

   int index = builder.indexOf(from);

   while (index != -1)

   {

       builder.replace(index, index + from.length(), to);

       index += to.length(); // Move to the end of the replacement

       index = builder.indexOf(from, index);

   }

}


출처: http://stackoverflow.com/questions/3472663/replace-all-occurences-of-a-string-using-stringbuilder

'Java' 카테고리의 다른 글

사이트 긁어오기  (0) 2015.08.19
mail 발송  (0) 2015.08.18
mybatis의 insert후 sequence 가져오기  (0) 2014.08.21
MS-SQL JDBC 추가하기.  (0) 2014.07.28
MIME 타입 알아내는 방법  (0) 2013.10.02
File file = new File(path + fileName);
file.toURL().openConnection().getContentType(); // 1
URLConnection.guessContentTypeFromName(orgFile.getName()); // 2
URLConnection.guessContentTypeFromStream(new BufferedInputStream(new FileInputStream(orgFile))); // 3
new MimetypesFileTypeMap().getContentType(orgFile); // 4
Files.probeContentType(Paths.get(orgFile.toURI())); // 5

위의 방법으로 엑셀 2007 형식의 파일을 분석했을때 오피스가 설치된 pc와 설치되지 않은 pc에서 각각 다른 반응을 보였다.


1. 설치된 pc

1 >>>>>>content/unknown

2 >>>>>>null

3 >>>>>>null

4 >>>>>>application/octet-stream

5 >>>>>>application/vnd.openxmlformats-officedocument.spreadsheetml.sheet


2. 설치되지 않은 pc

1 >>>>>>content/unknown

2 >>>>>>null

3 >>>>>>null

4 >>>>>>application/octet-stream

5 >>>>>>null


5번이 가장 정확한 내용을 알려주지만 경우에 따라서 null이 나올 수도 있으므로 4번이 가장 무난한 선택일수도 있겠다.


'Java' 카테고리의 다른 글

mybatis의 insert후 sequence 가져오기  (0) 2014.08.21
MS-SQL JDBC 추가하기.  (0) 2014.07.28
JSTL에서 substring, length  (0) 2013.09.26
EL 함수 추가하기  (0) 2013.09.10
Apache POI 추가  (0) 2013.08.22

+ Recent posts