Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ManipulaArquivo {
- public ManipulaArquivo() {
- }
- public List<String> abrirArquivo(String caminho) {
- List<String> texto = new ArrayList<>();
- File arq = new File(caminho);
- if (arq.exists()) {
- try {
- //OpenFile
- FileReader arquivo = new FileReader(caminho);
- BufferedReader conteudoDoArquivo = new BufferedReader(arquivo);
- String linha = conteudoDoArquivo.readLine();
- while (linha != null) {
- texto.add(linha);
- linha = conteudoDoArquivo.readLine();
- }
- conteudoDoArquivo.close();
- } catch (Exception e) {//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- }
- } else {
- texto.add("");
- }
- return texto;
- }
- public int salvarArquivo(String caminho, List<String> texto) {
- try {
- // Create file
- FileWriter arquivo = new FileWriter(caminho);
- BufferedWriter conteudoDoArquivo = new BufferedWriter(arquivo);
- for (int i = 0; i < texto.size(); i++) {
- conteudoDoArquivo.write(texto.get(i) + "\n");//+ System.getProperty("line.separator")); //
- }
- conteudoDoArquivo.close();
- } catch (Exception e) {//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- return 1; //houve erro
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment