a.txt 파일의 단어를 b.txt 파일의 단어와 함께 c.txt 파일에 교대로 병합하는 프로그램을 작성하여 a.txt 파일의 문자와 Carriage return ret
코드 사본은 다음과 같습니다.
패키지 javase.arithmetic;
import com.google.common.base.charsets;
import com.google.common.base.joiner;
import com.google.common.base.splitter;
import com.google.common.collect.lists;
import com.google.common.io.files;
import java.io.file;
import java.io.ioexception;
Java.util.list 가져 오기;
/**
* 사용자 : RealFighter
* 날짜 : 2015/3/10
* 시간 : 18:06
*/
공개 클래스 filetest {
/**
* a.txt 파일의 단어를 b.txt 파일의 단어와 함께 c.txt 파일에 a.txt 파일에 문자를 캐리지 리턴 문자와 함께 변경하는 프로그램을 번갈아 가려면 프로그램을 작성하십시오.
* B.txt 파일은 캐리지 리턴 또는 공간으로 분리됩니다.
*/
//a.txt //b.txt
/**
나 이것은 Java 프로그램입니다
내 이름은 Realfighter입니다
유
아기
*/
public static void main (String [] args)은 ioexception {
// a.txt b.txt에서 내용을 읽고 목록으로 변환합니다.
String apath = filetest.class.getClassLoader (). getResource ( "a.txt"). getPath ();
list alist = files.readlines (새 파일 (apath), charsets.utf_8);
문자열 bpath = filetest.class.getClassLoader (). getResource ( "b.txt"). getPath ();
list blist = files.readlines (새 파일 (bpath), charsets.utf_8);
awords = alist; // a.txt의 모든 단어
list bwords = lists.newarraylist (splitter.on ( "") .split (joiner.on ( "") .join (blist)); // b.txt의 모든 단어
Bigone = awords.size ()> = bwords.size () : bwords;
smallone = awords.size ()> = bwords.size () : awords;
stringBuffer from = new StringBuffer ();
for (int i = 0; i <smallone.size (); i ++) {
from.append (bigone.get (i)). Append ( "") .append (smallone.get (i)). Append ( "");
}
for (int j = smallone.size (); j <bigone.size (); j ++) {
from.append (bigone.get (j)). Append ( "");
}
// 파일에 씁니다
문자열 cpath = filetest.class.getClassLoader (). getResource ( "c.txt"). getPath ();
파일 = 새 파일 (cpath);
files.write (from, file, charsets.utf_8);
}
}
위의 코드는이 기사의 전체 내용입니다. 나는 당신이 그것을 좋아하기를 바랍니다.