내 프로그램으로 RTF 문서를 생성하고 싶습니다. 나는 RTFEditor
을 사용하여 rtfformat에서 편집 된 텍스트를 제공하지만, 역시 이 있고 TextFields에서 RTF Documeent로 문자열을 가져와야합니다. rtf 문서 텍스트를 편집하려고했지만 ANSI와 UTF-8로 인해이 성가신 인코딩 문제가 발생했습니다. 내 TextFields에 "äöüß"라는 문자열이있는 경우 ... "¶"과 같은 인코딩을 얻습니다. 내 목표는 인코딩 문제가없는 멋진 RTF 문서를 얻는 것입니다.RTF 형식으로 문자열 넣기
이 문제를 해결하는 가장 좋은 방법은 무엇입니까?
다음은 rtf 문서를 출력하는 클래스입니다. 참고 :이 코드의 중요한 부분에 집중하십시오. 내 코드에서 독일어 용어가 당신을 혼란스럽게하지 않기를 바랍니다 :).
/**
* Handles the Saving of a Protokoll to a .rtf file.
* The .executeSaving() method executes the process of saving.
* @author me
*/
public class WordExport {
// other methods...
/**
* Executes the saving-progress by the given file.
* Structure of the rtf-File:
* -------------------------
* HeadString |
* -------------------------
* Content |
* .. |
* .. |
* .. |
* .. |
* -------------------------
* @param file points to the target where the .rtf should be saved.
* @param protokoll The protokoll which you want to save.
* @throws IOException Thrown when something is not okay with the IO.
*/
public void executeSaving(File file, Protokoll protokoll) throws IOException
{
//I want to insert my HeaderString into a specific position so i have to split etc...
String content = new String();
content = protokoll.getInhalt();
String[] split = content.split("}", 3);
for(int i = 0; i < split.length ; i++)
{
if(!split[i].contains("}"))
{
split[i] += "}";
}
}
String teilnehmer = new String();
for (Profil p : protokoll.getTeilnehmer())
{
teilnehmer += p.toString() + "\\par\n ";
}
String headString = new String();
//HERE IS THE IMPORTANT CODE --> here i put my strings bare into the rtf-format and i dont know how to handle the encoding.
headString = "\\f1\\fs44\\i0\\b0\\ul\\cf1\\ "+ protokoll.getTitel() +" \\par\n" +
"\\par\n" +
"\\fs24\\ul0 Raum: "+ protokoll.getRaum() +"\\par\n" +
"Zeitraum: "+ protokoll.getZeitraum() +"\\par\n" +
"Datum: "+ protokoll.getErstellungsdatum().toString() +"\\par\n" +
"\\par\n" +
"Teilnehmer: \\par\n" +
teilnehmer +
"\\ul0\\par ";
split[2] = headString+ split[2];
//Converts the String[] from above to the string, which you need to write into the .rtf file.
StringBuilder builder = new StringBuilder();
for(String s : split)
{
builder.append(s);
}
content = builder.toString();
if(!file.exists())
{
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
}
}
중요하지만 관련이 있습니다. 코드의 식별자와 설명에 영어를 사용해야합니다. 코드를 세계와 언제 공유해야하는지 알 수 없습니다. 영어는 의사 소통과 협업을 훨씬 쉽게 만듭니다. 또한 영어를 쓸 때 더 능숙해질 것입니다. – Palec
내 첫 번째 프로젝트 중 하나이며 내 요점은 내 다음 프로젝트에서 수행 할 첫 번째 작업 중 하나입니다. – Rubinum