목록프로그래밍 (60)
GGYU
private static String getSha512(String plainText) { try { MessageDigest md = MessageDigest.getInstance("SHA-512"); byte[] bytes = plainText.getBytes(Charset.forName("UTF-8")); md.update(bytes); return Base64.encode(md.digest()); } catch (Exception e) { System.out.println("Sha512 error."); e.printStackTrace(); return null; } }
public static void base64() { String text = "ktko"; byte[] targetBytes = text.getBytes(); // Base64 인코딩 /////////////////////////////////////////////////// Encoder encoder = Base64.getEncoder(); byte[] encodedBytes = encoder.encode(targetBytes); // Base64 디코딩 /////////////////////////////////////////////////// Decoder decoder = Base64.getDecoder(); byte[] decodedBytes = decoder.decode(encodedByt..
package practice.iting.tistory.com; import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.io.OutputStream;import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.net.InetAddress;import java.net.ServerSocket;import java.net.Socket;import java.text.SimpleDateFormat;import java.util.Date; public class EchoServer { public static void m..
public int increase() { synchronized(this) { return ++count; } } public synchronized int increase() { return ++count; }
public class Test implements Runnable { int seq; public Test(int seq) { this.seq = seq; } public void run() { System.out.println(this.seq+" thread start."); try { Thread.sleep(1000); }catch(Exception e) { } System.out.println(this.seq+" thread end."); } public static void main(String[] args) { ArrayList threads = new ArrayList(); for(int i=0; i
// ExecutorService 인터페이스 구현객체 Executors 정적메서드를 통해 최대 스레드 개수가 2인 스레드 풀 생성 ExecutorService executorService = Executors.newFixedThreadPool(2); for(int i = 0; i < 10; i++){ Runnable runnable = new Runnable() { @Override public void run() { //스레드에게 시킬 작업 내용 ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executorService; int poolSize = threadPoolExecutor.getPoolSize();//스레드 풀 사이즈 얻기 Stri..
public void subDirList(String source){File dir = new File(source); File[] fileList = dir.listFiles(); try{for(int i = 0 ; i < fileList.length ; i++){File file = fileList[i]; if(file.isFile()){ // 파일이 있다면 파일 이름 출력System.out.println("\t 파일 이름 = " + file.getName());}else if(file.isDirectory()){System.out.println("디렉토리 이름 = " + file.getName()); // 서브디렉토리가 존재하면 재귀적 방법으로 다시 탐색subDirList(file.getCanoni..
try {InputStream a = new FileInputStream("C:\\mytext.txt"); byte[] buffer = new byte[BUFFER_SIZE];while(true){int i = a.read(buffer);System.out.println("hi : " + i);if ( i == -1 ) break;}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} OutputStream a = new FileOutputStream("C:\\mytext.txt") ;try {String b = "행복하단. 그런 말을 하고 있었으면서.";byte[] c = b.getBytes()..
public class FileTextWriteReadExample { public static void main(String[] args){ File inFile = new File("C:\\Users\\Public", "in.txt"); File outFile = new File("C:\\Users\\Public", "in.txt"); //==========================// // 텍스트 파일 쓰기 //==========================// BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(outFile)); bw.write("테스트 합니다."); bw.newLine(); bw.write("테스트 ..
import java.io.File;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.LineNumberReader; public class FileLineNumberReaderExam { public static void main(String[] args) { String path = "C:\\Users\\mjhwang\\Desktop"; String fileName = "test.txt"; LineNumberReader reader = null; try { reader = new LineNumberReader(new FileReader(new File(path, f..