2013-05-21 6 views
0

텍스트 파일의 줄을 정렬하고 사전 순으로 정렬하는 프로그램이 있지만 첫 단어의 첫 번째 문자는 대문자이고 그 단어는 첫 글자 대문자와 나는 그것을 어떻게하는지 모른다.위와 아래로 정렬하는 Java 변환

이 텍스트 파일입니다

산타, 당신은 단지 더 나은 단계를 조심해!

개가 창문에 얼마나 있습니까?

빠른 갈색 여우는 게으른 개 위로 뛰어 올랐다.

당신은 쿠스의 프로그래밍 시리즈를 읽었습니까?

그냥 이렇게 나아지지 않습니다! 여기

내 코드입니다 :

import java.io.*; 
import java.util.*; 

public class wordSorter { 
public static void main(String[] args) throws Exception { 
String firstTextFile = "prob10.in.txt"; 
String secondTextFile = "prob10.out.txt"; 
Scanner Document = null; 
PrintWriter NewFile = null; 
String inputFile = ""; 
String outputFile = ""; 

try{ 
    Document = new Scanner(new File(firstTextFile)); 
} 
catch(Exception e){ 
    System.out.println("Could not find " + firstTextFile); 
    System.exit(0); 
} 

try{ 
    NewFile = new PrintWriter(new FileOutputStream(secondTextFile, true)); 
} 
catch(Exception f){ 
    System.out.println("Could not find " + secondTextFile); 
    System.exit(0); 
} 

while (Document.hasNextLine()){ 
inputFile = Document.nextLine(); 
String line = inputFile; 
line = line.toLowerCase(); 
String[] words = line.split(" "); 

Arrays.sort(words); 
NewFile.println(Arrays.toString(words)); 
} 
Document.close(); 
NewFile.close(); 

} 

}

+0

에 대한 예제를 살펴이 있기 때문에 그것은 더 좋을 수도 그걸 Q에 넣으세요. 그렇지 않으면 가장 이상한 의견의 소품을 보았습니다. –

답변

0

Java's Collator에서보세요 ... 그리고 자바에 새가 Java CodeRanch

+0

그냥 거기 던져 버리고 나는 자바를 처음 접했고 방금 보낸 내용은 나에게 전혀 의미가 없다. – Logan

+0

죄송합니다. 사람들이 알고있는 정도를 어느 정도 알지 못합니다. 다음은 링크 예입니다. http://www.coderanch.com/t/492333/java/java/Case-Sensitive-sorting-Collator –