Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Legollas Dias

Codificação?!

Recommended Posts

Pessoas, aqui estou novamente. Seguinte, o msm programa do outro topico, no quebra de linha, quando executo ele no NetBeans, ele sai assim.

 

fruf.jpg

 

Bacana, quando limpo e construo o .jar. ele aparece assim.

 

22qe.jpg

 

Pois é, como puderam perceber, rodando direto no windows os acentos nao funcionam.

OBS¹: um amigo rodou o msm .jar no pc dele q roda Linux e funcionou.

OBS²: eh um programa para outra pessoa, para clicar e abrir essa janela ai, eu sei que pelo Prompt ele abre normalmente tbm.

Por favor alguem me ajude.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tentar forçar o encoding da String.

label.setText(new String("Seu texto com acento aqui.".getBytes(), "UTF-8"));

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigao da um help pls, vou colocar meu codigo aki pra vc me ajudar onde eu colocaria esse UTF-8 ai ok. se puder ajudar ficarei muito grato.

 

Classe escolhendoPensamento

public class escolhendoPensamento {
    private ArrayList<String> lista;

 public escolhendoPensamento() throws IOException { 
        lista = new ArrayList<>(); 
        File file = new File(("Pensamentos.txt"));
        if (file.exists()) {
            try (FileReader reader = new FileReader(file); 
                    
                    BufferedReader reader2 = new BufferedReader(reader)) {
                while (reader2.ready()) {
                    String linha = reader2.readLine();
                    //System.out.println(linha);
                    lista.add(linha);
                }
            }
        } else {
            System.out.println("Arquivo Inexistente");
        }
    }
   public String buscarPalavraAleatoria() {
        Random r = new Random();
        return lista.get(r.nextInt(lista.size()));
    }
 }

Classe numeroPensamento

 

public class numeroPensamentos  {
    
   public static int numeroPensamentos () throws FileNotFoundException{ 
                int numero = 0;
                String nomeArquivo = "Pensamentos.txt";
                String[] pensamento;  
                LineNumberReader lineCounter = new LineNumberReader(new InputStreamReader(new FileInputStream(nomeArquivo)));
String nextLine = null;


try {
while ((nextLine = lineCounter.readLine()) != null) {
if (nextLine == null)
break;
}
numero = lineCounter.getLineNumber();
} catch (Exception done) {
done.printStackTrace();
             
}
        return numero;
}
    
}

classe teste (main)

 

public class teste {


    public static void main(String args[]) throws IOException {
        escolhendoPensamento pensamento = new escolhendoPensamento();
        numeroPensamentos numero = new numeroPensamentos();
        JFrame frame = new JFrame("Pensamento sorteado entre os " + numeroPensamentos.numeroPensamentos()+" presentes na base");
        JLabel label = new JLabel("<html>" + pensamento.buscarPalavraAleatoria() + "<html>");
        label.setPreferredSize(new Dimension(650, 120));
        frame.getContentPane().add(label);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
        frame.setLocationRelativeTo(null);
         
    }
    }

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você pode fazer isso na leitura do arquivo.

BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("/caminho/para/arquivo")), "UTF8"));

String str;
while ((str = in.readLine()) != null) {
  // Seu código aqui...
}

in.close();

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.