[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Aspell-user] German Umlaut issue, how to accept "a as ??
From: |
Michael Gruenewald |
Subject: |
[Aspell-user] German Umlaut issue, how to accept "a as ?? |
Date: |
Tue, 11 Mar 2003 15:02:34 +0100 |
User-agent: |
Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 |
Hi, I have written a small java-prog to convert the files.
It searches for old values and replaces it with new values of the
corresponding index. It searches for all tex-files in the dirName
creates a backup and replace the old files.
I hope anybody will find this prog useful.
Greetings Michael
/**
* <p>Title: ReplaceUmlaute</p>
* <p>Description: Erstetzt die Umlaute, für aspell.</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Student</p>
* @author Michael Grünewald
* @version 0.01
*/
import java.io.*;
public class ReplaceUmlaute{
public static String[] oldValues
={"\"a","\"o","\"u","\"s","\"A","\"O","\"U"};
public static String[] newValues ={"ä","ö","ü","ß","Ä","Ö","Ü"};
public static String dirName = "I:\\Diplom\\DiplomText";
public static String backupDirName =
"I:\\Diplom\\DiplomText\\BackupDir";
public static String suffix ="tex";
public static void main(String[] args) {
File dir = new File(dirName);
File backupDir = new File(backupDirName);
if ( dir.exists() && dir .canRead()){
File[] files = dir.listFiles(new FilenameFilter(){
public boolean accept(File dir, String name){
if (name.length() >= 4 && name.indexOf(".") > 0 ){
String compare =
name.substring(name.length() - suffix.length());
if (compare.equalsIgnoreCase(suffix))
return true;
}
return false;
}
});
boolean success = false;
if ( !backupDir.exists()) success = backupDir.mkdir();
else success = true;
for (int i = 0; i < files.length; i++){
File file = files[i];
FileReader fin = null;
BufferedReader in = null;
FileWriter fout = null;
PrintWriter out = null;
FileWriter bfout = null;
PrintWriter bout = null;
FileReader copyfin = null;
BufferedReader copyIn = null;
FileWriter copyfout = null;
PrintWriter copyOut = null;
File backup = null;
try {
File targetFile =
File.createTempFile("temp","tex",backupDir);
// Backup
if (success){
String filename = files[i].getAbsolutePath();
int pos = filename.lastIndexOf(File.separator);
if (pos > 0) filename =
filename.substring(pos);
filename = backupDirName + filename;
backup = new File(filename);
if ( backup.exists() ) backup.delete();
backup.createNewFile();
}
fin = new FileReader(file);
in = new BufferedReader(fin);
fout = new FileWriter(targetFile);
out = new PrintWriter(fout);
if (backup != null){
bfout = new FileWriter(backup);
bout = new PrintWriter(bfout);
}
while(in.ready()){
String currentLine = in.readLine();
if (bout != null) bout.println(currentLine);
//backup
for (int j= 0; j < oldValues.length; j++){
int pos = currentLine.indexOf(oldValues[j]);
while (pos >= 0){
currentLine =
currentLine.substring(0,pos) + newValues[j] +
currentLine.substring(pos+oldValues[j].length());
pos = currentLine.indexOf(oldValues[j]);
}
}
out.println(currentLine);
}
if (bout != null) bout.flush();
out.flush();
in.close();
// replace old file with new file (temp file)
file.delete();
file.createNewFile();
copyfin = new FileReader(targetFile);
copyIn = new BufferedReader(copyfin);
copyfout = new FileWriter(file);
copyOut = new PrintWriter(copyfout);
while(copyIn.ready())
copyOut.println(copyIn.readLine());
copyOut.flush();
copyIn.close();
targetFile.delete();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
try {
if (in != null) in.close();
if (fin != null) fin.close();
if (out != null) out.close();
if (fout != null) fout.close();
if (copyIn != null) copyIn.close();
if (copyfin != null) copyfin.close();
if (copyOut != null) copyOut.close();
if (copyfout != null) copyfout.close();
}
catch (Exception ex) {
}
}
}
}
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Aspell-user] German Umlaut issue, how to accept "a as ??,
Michael Gruenewald <=