Commit 8c27098a authored by Deokhyun Lee's avatar Deokhyun Lee

initial

parents
Pipeline #2084 canceled with stages
File added
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/JavaFileManagement.iml" filepath="$PROJECT_DIR$/JavaFileManagement.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import com.hsj.util.Util;
public class Main {
public static void main(String[] args) {
// write your code here
String filePath = "/Users/ideoghyeon/Desktop/이름.txt";
Util.smartReadLineFile(filePath, "\n", ",");
}
}
package com.hsj.util;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class Util {
// 오늘 날짜를 가져 오는 메소드(yyyy-MM-dd)
public static String getCurrentDate(String fmt) {
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
return sdf.format(new Date());
}
// 파일 읽어서 화면에 출력(파일 내용을 여기 메소드 밖으로 보내고 싶다)
public static String readLineFile(String filePath) {
BufferedReader br = null;
String retLine = "";
// StringBuffer sb = new StringBuffer();
try {
br = new BufferedReader(new FileReader(filePath));
while (true) {
String line = br.readLine();
if (line == null)
break;
retLine += line + "\n"; // 문자열을 리턴
// sb.append(line + "\n");
// System.out.println(line); // 화면에 출력
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return retLine; // sb.toString()
// return sb.toString();
}
/**
* 간편하게 split을 이용할 수 있다.
*
*/
public static void smartReadLineFile(String filePath, String separator, String separator2) {
BufferedReader br = null;
String retLine = "";
try {
br = new BufferedReader(new FileReader(filePath));
while (true) {
String line = br.readLine();
if (line == null)
break;
retLine += line + "\n";
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String[] strArr = retLine.split(separator);
for (String s : strArr) {
String[] tmpArr = s.split(separator2);
System.out.print("번호: " + tmpArr[0] + " / ");
System.out.print("이름: " + tmpArr[1] + " / ");
System.out.println("전공: " +tmpArr[2]);
}
}
// 파일 쓰기(새파일로 쓰기, 덮어쓰기)
public static void writeLineFile(ArrayList<String> strList, String filePath) {
PrintWriter out = null;
try {
out = new PrintWriter(filePath);
for(String s : strList) {
out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
}
// 파일 쓰기(이어 쓰기)
public static void writeLineFile(ArrayList<String> strList, String filePath, boolean isAppend) {
PrintWriter out = null;
try {
out = new PrintWriter(new FileWriter(filePath, isAppend));
for(String s : strList) {
out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
out.close();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment