Bueno estoy tratando de solucionar esto,se trata de poder validar un archivo de texto que contiene 1 y 0 que conforman una imagen,donde de un programa java lo mando a llamar y me pinta la imagen en un jpanel,ahora lo que yo quiero hacer es poder validarlo que si esta en el archivo 0111*+´/ cualquier otro simbolo me marque error para esto trate de hacer lo siguiente:
Código
import java.text.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.StringTokenizer;
import javax.swing.*;
import javax.swing.JFileChooser;
// Clase
class dibujo extends Frame {
static String cad=" ";
public static String dir="";
// Función de control de la aplicación
public static void main( String[] gll ) throws IOException{
try{
dir= JOptionPane.showInputDialog(null,"Escribe solo el nombre del archivo a ejecutar"+" ","micky.isc");
int a=dir.length(),b=a-4;
String sub=dir.substring(b,dir.length()),sub2=".isc";
System.out.println(sub);
if (sub.equals(sub2)){
//compara imagen
FileReader ab = new FileReader(dir);
BufferedReader cd = new BufferedReader(ab);
int numlineas = 0,total=0;
String Cadena="";
while ((Cadena = cd.readLine())!=null) {
numlineas++;
cad += Cadena+"\n";
aqui en el while no se si desde aqui lovalido ya que me lee el archivo txt...
}
}
else
{
JOptionPane.showMessageDialog(null, "Formato no Reconocido","Error",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
catch (FileNotFoundException e){
e.printStackTrace();
}
catch (IOException d){
d.printStackTrace();
}
new dibujo();
}
public dibujo() {
this.setTitle( "Dibujo" );
this.setSize( 350,350 );
this.setVisible( true );
this.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent evt ) {
System.exit( 0 );
}
} );
}
public void paint(Graphics g){
g.translate( this.getInsets().left,this.getInsets().top );
byte[] sep = cad.getBytes();
String acep="falso";
System.out.println ("hacker " +sep[2]);
if (cad.length() >= 1000){
int x=0,y=0;
for(int i=0; i<sep.length; i++){
if (sep[i] == 48 || sep[i] == 49 || sep[i]==10 ||sep[i]==255 )
{
if (sep[i]==48){
g.setColor(Color.white);
g.fillRect( x+70,y+50,1,1);
x=x+1;
}
if (sep[i] == 49){
g.setColor(Color.black);
g.fillRect( x+70,y+50,1,1 );
x=x+1;
}
if (sep[i]== 10){
y=y+1;
x=0;
}
}////
else{
/////////////////////
aqui esta mi duda le digo que si existe cualquier digito o caracter de 48=1 y 49=0
me mande error pero no entra en el ciclo mi pregunta es por que!
if (!(sep[i]==48)&&!(sep[i] == 49)){
System.out.println("eror"+sep[i]);
}
System.out.println("error");
}
}
}
else
{
JOptionPane.showMessageDialog(null,"Tu Imagen no es la Correcta","Mensage",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
}
bueno espero me haya dado entender,espero me puedan ayudar...saludos...










Autor




En línea


