JAVA2014. 4. 19. 11:31


[JAVA] FilenameFilter 를 이용한 특정 확장자 파일리스트 가져오기


하위디렉토리 폴더와 파일 읽기


import java.io.*; 

import java.util.ArrayList;

import java.util.Collections; 



public class folderInReader {



    private static ArrayList<String> list = new ArrayList<String>(); 

    

public static void main(String[] args) throws IOException {


        String message = null;

        String filePath = ".";

        File path = new File( filePath );

        

        if( path.exists() == false ){

            System.out.println("경로가 존재하지 않습니다");

        }

        File[] fileList = path.listFiles();

        

        int tab = 1;

        for( int i = 0 ; i < fileList.length ; i++ ){

            if( fileList[ i ].isDirectory() ){

                message = "[디렉토리] ";

                message += fileList[ i ].getName();

                System.out.println( message );

                subDirList(  fileList[ i ].getName(), tab);

               

                Collections.reverse(list); 

                

                for(String str:list) {

                System.out.println(str);

                }

                

                list.clear();

                                             

            }else{

                message = "[파일] ";

                message += fileList[ i ].getName();

                System.out.println( message );

            }

            

        }

        

    } 

private static void subDirList(String source, int tab){

File dir = new File(source); 

File[] fileList = dir.listFiles(); 

 

String sTab = "";

for ( int i =0 ; i < tab ; i++){

sTab +="\t";

}

try{

for(int i = 0 ; i < fileList.length ; i++){

File file = fileList[i]; 

if(file.isFile()){

    // 파일이 있다면 파일 이름 출력

if( i==0 ){

//System.out.println("[디렉토리 이름] = " + dir.getPath()   );

list.add("[디렉토리 이름1] = " + dir.getPath() ) ;

}

//System.out.println(sTab + " 파일 이름 = " + file.getName());

list.add(sTab + " 파일 이름 = " + file.getName() );

}else if(file.isDirectory()){ 

    // 서브디렉토리가 존재하면 재귀적 방법으로 다시 탐색

subDirList(file.getCanonicalPath().toString(),tab+1);

list.add("[디렉토리 이름2] = " + dir.getPath() );

//System.out.println("[디렉토리 이름] = " + dir.getPath()   );

}

}

}catch(IOException e){

}

 

}



}



'JAVA' 카테고리의 다른 글

[펌]jar 내부 파일 읽기  (0) 2014.04.19
[펌]Java Architecture for XML Binding (JAXB) 예제  (0) 2014.03.03
[ERROR] java 오류 정리  (0) 2014.02.26
Socket으로 Mail 전송 샘플  (0) 2014.02.24
SMTP 서버를 통해 메일 전송  (0) 2014.02.19
Posted by 선한열심
JAVA2014. 4. 19. 09:34

[펌] http://cs.dvc.edu/HowTo_ReadJars.html



실행방법 : java JarRead JA파일명  경로/../읽을파일명   

예) java JarRead jersey-server-2.2.jar org/glassfis

h/jersey/server/wadl/processor/WadlModelProcessor.class


import java.io.*;

import java.util.jar.*;


public class JarRead 

{

  public static void main (String args[]) throws IOException 

  {

 System.out.println ("args.length=" + args.length );

    if (args.length != 2) 

    {

      System.out.println("Please provide a JAR filename and file to read");

      System.exit(-1);

    }

    JarFile jarFile = new JarFile(args[0]);

    JarEntry entry = jarFile.getJarEntry(args[1]);

    InputStream input = jarFile.getInputStream(entry);

    process(input);

  }


  private static void process(InputStream input) throws IOException 

  {

    InputStreamReader isr = new InputStreamReader(input);

    BufferedReader reader = new BufferedReader(isr);

    String line;

    while ((line = reader.readLine()) != null)

      System.out.println(line);

    reader.close();

  }

}

Posted by 선한열심
JAVA2014. 3. 3. 13:40

출처 - http://http://www.vogella.com/tutorials/JAXB/article.html

Book.java

 

BookMain.java

 

Bookstore.java

 

 

'JAVA' 카테고리의 다른 글

하위디렉토리 폴더와 파일 읽기  (0) 2014.04.19
[펌]jar 내부 파일 읽기  (0) 2014.04.19
[ERROR] java 오류 정리  (0) 2014.02.26
Socket으로 Mail 전송 샘플  (0) 2014.02.24
SMTP 서버를 통해 메일 전송  (0) 2014.02.19
Posted by 선한열심
JAVA2014. 2. 26. 18:24

 


[오류] com.ibatis.common.jdbc.exception.NestedSQLException
[해결] 쿼리 안에 -- #파라미터#  를 주석으로 처리했을 경우 발생할 수 있음

 
[오류]tms.rsf.client.RESTClient.createUri(RESTClient.java)
[해결]호출 URI에 공백이 있거나 잘못 되었을 경우, URI 확인하자

 

 

[오류] java.lang.NoClassDefFoundError: javax/mail/Address 
 mail.jar download: http://www.oracle.com/technetwork/java/index-138643.html
 activation.jar download: http://java.sun.com/products/archive/javabeans/jaf102.html

 mail.jar 톰캣의 lib 폴더에 넣고 서버 다시실행하면된다
 


[오류] java.lang.NoClassDefFoundError: org/springframework/web/util/Log4jConfigListener
[해결]
  1. ?? 이클립스 Project explorer에서 프로젝트 refresh 하고
  2. 이클립스 다시 실행
  3. jboss 재시작하면 없어짐 
 주의)  로그파일 Log4jConfigListener error 위에 다른 오류 있을 수 있음


[오류]-[JSTL] The method setText(boolean) in the type IfTag 오류 
출처 - http://pwu-developer.blogspot.kr/2009/11/jstl-test-condition-and-trailing-spaces.html
원인 : <c:if test="${not empty sp.mouse.strain}         "> 의 공백
해결 : <c:if test="${not empty sp.mouse.strain}"> 공백 없앰으로 오류해결
 

 

'JAVA' 카테고리의 다른 글

[펌]jar 내부 파일 읽기  (0) 2014.04.19
[펌]Java Architecture for XML Binding (JAXB) 예제  (0) 2014.03.03
Socket으로 Mail 전송 샘플  (0) 2014.02.24
SMTP 서버를 통해 메일 전송  (0) 2014.02.19
java.lang.reflect.Method 샘플  (0) 2013.12.05
Posted by 선한열심
JAVA2014. 2. 24. 14:55


import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;

class SocketMailTest
{
    public static void main(String[] args)
    {
        Socket socket = null;
        System.setProperty("line.separator", "\r\n");

        try {

            socket = new Socket("서버IP",서버PORT);  

            String forward = "jungws55@nate.com";        
            String reverse = "jungws55@naver.com";          
            String replyto = reverse;                    
            String subject = "Hello World";              

          
            String content = "<html><body><h2>Hello World</h2> </body></html>";

            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter pw = new PrintWriter(socket.getOutputStream(),true);

            sendAndReceive(null, rd, pw);
            sendAndReceive("HELO mtarget.cn", rd, pw);
            sendAndReceive("MAIL FROM:<" + reverse + ">", rd, pw);
            sendAndReceive("RCPT TO:<" + forward + ">", rd, pw);
            sendAndReceive("DATA", rd, pw);

            pw.println("Subject:" + subject);
            pw.println("From:<"+ reverse +">");
            pw.println("To:<"+ forward +">");
            pw.println("Reply-To:<"+ replyto +">");
            pw.println("Date:" + (new Date()));
            pw.println("Mime-Version: 1.0;");
            pw.println("Content-Type: text/html;");
            pw.println("charset=\"utf-8\";");
            pw.println();
            pw.println();
            pw.println(content);
            pw.flush();

            sendAndReceive(".", rd, pw);
            sendAndReceive("QUIT", rd, pw);

        } catch (Exception e) {

        }

        if (socket != null) {

            try {
                socket.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void sendAndReceive(String text, BufferedReader br, PrintWriter pw)  throws IOException {

            if (text != null) {
                System.out.println("Client> " + text);
                pw.println(text);
                pw.flush();
            }

            String response;
            if ((response = br.readLine()) != null) {
                System.out.println("Server> " + response);
            }
    }
}

'JAVA' 카테고리의 다른 글

[펌]Java Architecture for XML Binding (JAXB) 예제  (0) 2014.03.03
[ERROR] java 오류 정리  (0) 2014.02.26
SMTP 서버를 통해 메일 전송  (0) 2014.02.19
java.lang.reflect.Method 샘플  (0) 2013.12.05
Annotation Example  (0) 2013.12.05
Posted by 선한열심
JAVA2014. 2. 19. 16:07

인증없이 전송 샘플 : http://blog.daum.net/_blog/BlogTypeView.do?blogid=0fK9x&articleno=618

전송 샘플 : http://kodejava.org/how-do-i-send-an-email-with-attachment/

                http://blog.naver.com/PostView.nhn?blogId=hmleena&logNo=63968842

 

윈도우7 SMTP 설치 : http://blog.naver.com/PostView.nhn?blogId=livingsens&logNo=40186294416&redirect=Dlog&widgetTypeCall=true

 

 

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleMailTest {
    public static void main(String[] args) {    
        try {
            Properties props = new Properties();
            //props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.host", "서버IP");
            props.put("mail.smtp.port", "서버PORT");      
            props.put("mail.smtp.auth", "false"); 
            //props.put("mail.smtp.starttls.enable","true");
            Authenticator authenticator = new Authenticator()
            {
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication(null,null);
              }
            };
            //props.put("mail.smtp.auth", "true"); 
            //props.put("mail.smtp.starttls.enable", "false");   
            System.out.println( "2" );
            Session session = Session.getInstance(props) ;
            //Session session = Session.getDefaultInstance(props) ;
            System.out.println("2");
           
           
            InternetAddress fromAddress = new InternetAddress("jungws55@daum.net");
            InternetAddress toAddress   = new InternetAddress("jungws55@nate.com");
           

            MimeMessage message = new MimeMessage(session);
            message.setFrom(fromAddress);
            message.addRecipient(Message.RecipientType.TO, toAddress );
            message.setSubject("제목");
            message.setContent("내용"," text/html; charset=KSC5601");
            Transport.send(message);
            System.out.println("[{}] 메일 발송 성공 jungws55@nate.com");


         } catch (MessagingException e) {
             System.out.println(e);
         }


     }
}

 

'JAVA' 카테고리의 다른 글

[ERROR] java 오류 정리  (0) 2014.02.26
Socket으로 Mail 전송 샘플  (0) 2014.02.24
java.lang.reflect.Method 샘플  (0) 2013.12.05
Annotation Example  (0) 2013.12.05
static 키워드  (0) 2013.12.04
Posted by 선한열심
JAVA2013. 12. 5. 13:27

출처 - http://mysnyc.tistory.com/42

'JAVA' 카테고리의 다른 글

Socket으로 Mail 전송 샘플  (0) 2014.02.24
SMTP 서버를 통해 메일 전송  (0) 2014.02.19
Annotation Example  (0) 2013.12.05
static 키워드  (0) 2013.12.04
날짜 형식에서 .0 빼기  (0) 2013.10.16
Posted by 선한열심
JAVA2013. 12. 5. 10:49

샘플 코드는 맨 아래 있음 (Demo)


http://isagoksu.com/2009/development/java/creating-custom-annotations-and-making-use-of-them/

'JAVA' 카테고리의 다른 글

SMTP 서버를 통해 메일 전송  (0) 2014.02.19
java.lang.reflect.Method 샘플  (0) 2013.12.05
static 키워드  (0) 2013.12.04
날짜 형식에서 .0 빼기  (0) 2013.10.16
스트링 비교  (0) 2013.09.26
Posted by 선한열심
JAVA2013. 12. 4. 18:08

1. 



자세한설명 : http://rockdrumy.tistory.com/214

'JAVA' 카테고리의 다른 글

java.lang.reflect.Method 샘플  (0) 2013.12.05
Annotation Example  (0) 2013.12.05
날짜 형식에서 .0 빼기  (0) 2013.10.16
스트링 비교  (0) 2013.09.26
[JAVA] 공부 ,유용한 사이트  (0) 2013.07.19
Posted by 선한열심
JAVA2013. 10. 16. 18:12

날짜 형식 2013-10-25 13:15:14.0


str.replaceAll("\\.0","") 



'JAVA' 카테고리의 다른 글

Annotation Example  (0) 2013.12.05
static 키워드  (0) 2013.12.04
스트링 비교  (0) 2013.09.26
[JAVA] 공부 ,유용한 사이트  (0) 2013.07.19
[펌]소프트웨어 개발보안(시큐어 코딩) 관련 가이드  (0) 2013.07.16
Posted by 선한열심