Created
June 26, 2015 18:02
-
-
Save danilomiranda/9a6674894cfaf1034530 to your computer and use it in GitHub Desktop.
Dividir arquivo CSV em arquivos menores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String charset = "Cp1252"; | |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream("CAMINHO ARQUIVO ORIGEM"), charset)); | |
String line=""; | |
String destiny="CAMINHO ARQUIVO DESTINO"; | |
int count = 1; | |
int fileSize = 0; | |
OutputStreamWriter fos = new OutputStreamWriter(new FileOutputStream(destiny+count+".csv"),charset); | |
while((line = bufferedReader.readLine()) != null) { | |
if(fileSize + line.getBytes().length > 50 * 1024 * 1024){ | |
fos.flush(); | |
fos.close(); | |
count++; | |
fos = new OutputStreamWriter(new FileOutputStream(destiny+count+".csv"),charset); | |
fos.write(line+"\n"); | |
fileSize = line.getBytes().length; | |
}else{ | |
fos.write(line+"\n"); | |
fileSize += line.getBytes().length; | |
} | |
} | |
fos.flush(); | |
fos.close(); | |
bufferedReader.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment