본문 바로가기

장기 프로젝트/JAVA

spring java 파일 삭제 코드 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import java.io.File; public class FileDeletionExample { public static void main(String[] args) { // 삭제할 파일 경로 String filePath = "C:\\example\\file.txt"; // File 객체 생성 File file = new File(filePath); // 파일이 존재하는지 확인 if (file.exists()) { // 파일 삭제 file.delete(); System.out.println("파일이 삭제되었습니다."); } else { System.out.println("파일이 존재하지 않습니다."); } } .. 더보기
java에서 서버이름 가져오기 java 소스 private void processSessionCookie(HttpSession session){ Cokie cookie = new Cookie("SSIONID", session.getid()); String contextpath = getContextPath(); cookie.sePath(contextpath)' response.addCookie(cookie) setAttribue("COOKIE_OVERWRITTEN_FLAG", true); } jsp 화면 더보기
엑셀 다운로드 @RequestMapping("/potal/excelDownload.do") public void excelDownload(modelMap model, HttpServletRequest request, httpServletResponse response, @ModelAttribute("exVo") ExVO vo) throws Exception { List list1 = assService.userlistExcel(vo); List list2 = assService.userlistExcel2(vo); Map(String, Object> beans = new HashMap(); beans.put("list1" list1); beans.put("list2" list2); MakeExcel me = new Ma.. 더보기
[JAVA]숫자외 항목 체크 //숫자외 항목있는지 체크 private boolean checkNumberForm(String s){ if(countChar(s,".") > 1){ return false; } double number = Double.parseDouble(s); Strign checkNumber = Strigfn.format("$.3f", numbr); rerurn checkNumbr.trim().replaceAll("[.0-9]","").equals("") ? true : false; } //소수점 2번 입력 체크 private int countChar(String str, String ch){ return str.length() - str.replace(String.valueOf(ch),"").length(); }.. 더보기
임시번호 생성(JAVA) 방법 String randomPwd = _getRandomPassword(10) private String _getRandomPassword(int len){ char[] charSet = new char[] {''0,'1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'} int idx = 0; StringBuffer sb = new StringBuffer(); for(int i = 0; i < len; i++){ idx = (int) (charSet.length * Math.random()); sb.append(c.. 더보기
[JAVA] 알고리즘-수박수박수박 //내가 만든 JAVA 수박수박public class WaterMelon {public String watermelon(int n){String a = "수";String b = "박"; String sum = ""; for(int i=0; i 더보기
[JAVA] 알고리즘-짝수와 홀수 //내가 만듬 java 짝수와 홀수public class EvenOrOdd { String evenOrOdd(int num) { String result = ""; if(num % 2 == 0){ result = "Even"; }else if(num % 2 == 1){ result = "Odd"; } return result; } public static void main(String[] args) { String str = "1 2 3 4"; EvenOrOdd evenOrOdd = new EvenOrOdd(); //아래는 테스트로 출력해 보기 위한 코드입니다. System.out.println("결과 : " + evenOrOdd.evenOrOdd(3)); System.out.println("결과 : ".. 더보기
[JAVA] 알고리즘-평균값구하기 //내가 만든 java 평균값 구하기public class GetMean { public int getMean(int[] array) { int sum = 0; int num = array.length; int avg = 0; for(int i = 0 ; i 더보기