- Published on
SPIP Transform
- Authors
- Name
- Arnaud Ferrand
- @arferrand
This unpretentious little java program allows you to transform a csv file into a table file for SPIP
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Iso3166 {}
{
public static void main(String[] args) {
if( args.length < 1 ) {
System.out.println("Usage java Iso3166 FileIn [FileOut]");
System.exit(-1);
}
String outFileName = null;
String inFileName = null;
switch(args.length ) {
case 2 :
outFileName = args[1];
case 1 :
inFileName = args[0];
}
if( outFileName == null ) {
outFileName = inFileName + ".out";
}
try {
FileReader fr = new FileReader(inFileName);
BufferedReader br = new BufferedReader(fr);
FileWriter fw = new FileWriter(outFileName);
BufferedWriter bw = new BufferedWriter(fw);
String line = br.readLine();
while( line != null ) {
line = line.replace(';', '|');
String ecrire = String.format("%1$s%2$s%1$s", new Object[]{"|",line});
bw.write(ecrire);
bw.newLine();
line = br.readLine();
}
bw.close();
fw.close();
br.close();
fr.close();
} catch(FileNotFoundException fnfe) {
System.out.println(fnfe.getMessage());
} catch(IOException ioe) {
System.out.println(ioe.getMessage());
}
}
}