txt 파일의 각 줄에 문자를 삽입하는 방법이 궁금하십니까?txt 파일의 각 줄에 문자를 삽입하는 방법
예를 들어, 내가 txt 파일을 가지고과 같은 라인이 위치 :
text
text
text
내가 선이으로 같은 것을 만들 것 : 나는 시도하고있어
$text
$text
$text
정의는 사전
패키지 org.kodejava.example.io에서 솔루션 파이썬이나 자바 중 하나
감사;
import java.io. *;
public class Root {
public static void main(String[] args) {
File file = new File("C:\\text.txt");
StringBuilder contents = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
String text = null;
// repeat until all lines is read
while ((text = reader.readLine()) != null) {
contents.append(text)
.append(System.getProperty(
"line.separator"));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
// show file contents here
System.out.println(contents.toString());
}
}
내가 특정 기호를 삽입하기 위해 사용한다 Methos는 어떻게 파일을 읽을 수있는 샘플을 발견했습니다?
줄 단위로 파일을 읽고 줄에 새 문자를 추가하고 결과를 새 파일에 씁니다. – jtahlborn
먼저 시도해보십시오. 문제가 발생하면 여기로 돌아와서 이유를 물어 보면 도움을받을 수 있습니다. – mgilson
동의 - 어떤 언어를 사용하고 있는지 파악할 수 없다면 누군가가 대신 해주기를 바랄 것입니다. –