Foros del Web » Programación para mayores de 30 ;) » Java »

cómo compilar un archivo

Estas en el tema de cómo compilar un archivo en el foro de Java en Foros del Web. hola, estoy intentado compilar un archivo.java para ejecutarlo en mi mac. Es un buscador de fotos a través de un listado tab de códigos de ...
  #1 (permalink)  
Antiguo 28/03/2007, 05:23
 
Fecha de Ingreso: marzo-2007
Mensajes: 1
Antigüedad: 17 años, 1 mes
Puntos: 0
cómo compilar un archivo

hola, estoy intentado compilar un archivo.java para ejecutarlo en mi mac.

Es un buscador de fotos a través de un listado tab de códigos de fotos.jpg
El script lo que hace es desde un listado de un archivo buscafotos.tab busca las fotos en el ordenador y me crea una carpeta en el escritorio con las fotos encontradas.

Me he bajado el programa XCODE, pero no sé como hacerlo

El código es el siguiente

//
// buscafoto.java
//
//
// Created by Ordenador 1 on 28/03/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//

public class buscafoto {private static HashMap ficheros_fin = new HashMap();
private static HashMap resoluciones_fin = new HashMap();
private static Vector ficheros_ini = new Vector(1);

private static void buscar(File directorio)
{
if(directorio!=null)
{
if(directorio.isDirectory())
{
System.out.println("Buscando en "+ directorio.getName());
File[] lista = directorio.listFiles();
for (int i = 0; i < lista.length; i++)
{
if(lista[i].isFile())
{
String nombre_sinextension = "";
if(lista[i].getName().lastIndexOf(".")!=-1) nombre_sinextension = lista[i].getName().substring(0, lista[i].getName().lastIndexOf("."));
else nombre_sinextension = lista[i].getName();
String extension = getExtension(lista[i].getName());
//System.out.println("extension:"+ extension);
String nombre_jpg = (lista[i].getName());
if(ficheros_ini.contains(nombre_sinextension))
{
System.out.println("Encontrado "+ lista[i].getAbsolutePath());
//es un fichero de los que vamos buscando
//calcular resolucion
if(extension.equals("jpg"))
{
int resolucion_actual = 0;
try
{
JpgImage ji = new JpgImage(lista[i].getAbsolutePath());
resolucion_actual = ji.getHeight() * ji.getWidth();
} catch(Exception e) { System.out.println("Exception ji:"+ e); }
System.out.println("Resolucion de "+ nombre_jpg +" : "+ resolucion_actual);
//ver si est· en en HashMap ficheros_fin
if(ficheros_fin.containsKey(nombre_jpg))
{
int resolucion_vieja = ((Integer)resoluciones_fin.get(nombre_jpg)).intVal ue();
System.out.println("Resolucion vieja:"+ resolucion_vieja +" - actual:"+ resolucion_actual);
if(resolucion_vieja < resolucion_actual)
{
//si lo est·, miramos si la resoluciÛn (hxv) es mayor de la del hashmap
//si lo es quitamos la vieja y aÒadimos la nueva
ficheros_fin.put(nombre_jpg,lista[i].getAbsolutePath());
resoluciones_fin.put(nombre_jpg,new Integer(resolucion_actual));
System.out.println("Fichero reemplazo: "+ nombre_jpg +" - "+ resolucion_actual);
}
}
else
{
//es la primera vez que se encuentra el fichero
ficheros_fin.put(nombre_jpg,lista[i].getAbsolutePath());
resoluciones_fin.put(nombre_jpg,new Integer(resolucion_actual));
System.out.println("Fichero nuevo: "+ nombre_jpg +" - "+ resolucion_actual);
}
}
else
{
//extension no jpg
if(!ficheros_fin.containsKey(nombre_jpg))
{
ficheros_fin.put(nombre_jpg,lista[i].getAbsolutePath());
}
}
}
}

else if(lista[i].isDirectory())
{
buscar(lista[i]);
}

}
}
}

}
public static void main(String[] args) {
try
{
String ruta1 = "/Users/MIGUEL";
//String ruta2 = "/Volumes/320GB/320GB";
//String ruta3 = "/Volumes/digitales/digitales";
//String ruta4 = "/Volumes/digitalizadas/digitalizadas";
String directorio_destino = "/Users/MIGUEL/Desktop/fotos_encontradas";
String fichero_ini = "/Users/MIGUEL/Desktop/buscafotos.tab";
File dir1 = new File(ruta1);
//File dir2 = new File(ruta2);
//File dir3 = new File(ruta3);
//File dir4 = new File(ruta4);
File dir_destino = new File(directorio_destino);
//cargar lista de fotos a buscar en Vector
String str = "";
BufferedReader br = new BufferedReader(new FileReader(fichero_ini));
System.out.println("cargando...");
while((str = br.readLine()) != null)
{
//carga nombre ficheros sin extension
str = str.trim();
String nombre_kk = str.substring(0, str.lastIndexOf("."));
//
ficheros_ini.addElement(nombre_kk);
System.out.println("carga:"+ nombre_kk);

}
br.close();
System.out.println("fin carga datos.");
//buscar fotos
buscar(dir1);
buscar(dir2);
buscar(dir3);
buscar(dir4);
//copiar fotos encontradas a directorio destino
if(!dir_destino.exists()) dir_destino.mkdirs();
Iterator keyIter = ficheros_fin.keySet().iterator();
while(keyIter.hasNext())
{
String c_foto = (String)keyIter.next();
try
{
File aux = new File(""+ficheros_fin.get(c_foto));
if(aux.exists())
{
copy(""+ficheros_fin.get(c_foto), directorio_destino+"/"+ c_foto);
}

} catch(Exception e) { System.out.println(e); }
}

} catch(Exception e) { System.out.println(e); }

} // fin main()

public static String getExtension(String f) {
String ext = null;
String s = f;
int i = s.lastIndexOf('.');

if (i > 0 && i < s.length() - 1) {
ext = s.substring(i+1).toLowerCase();
}
return ext;
}

public static void copy(String source_name, String dest_name)
throws IOException
{
File source_file = new File(source_name);
File destination_file = new File(dest_name);
FileInputStream source = null;
FileOutputStream destination = null;
byte[] buffer;
int bytes_read;

try {
// First make sure the specified source file
// exists, is a file, and is readable.
if (!source_file.exists() || !source_file.isFile())
throw new FileCopyException("FileCopy: no such source file: " +
source_name);
if (!source_file.canRead())
throw new FileCopyException("FileCopy: source file " +
"is unreadable: " + source_name);
File parentdir = parent(destination_file);
if (!parentdir.exists())
throw new FileCopyException("FileCopy: destination "
+ "directory doesn't exist: " + dest_name);
if (!parentdir.canWrite())
throw new FileCopyException("FileCopy: destination "
+ "directory is unwriteable: " + dest_name);
//}

// If we've gotten this far, then everything is okay; we can
// copy the file.
source = new FileInputStream(source_file);
destination = new FileOutputStream(destination_file);
buffer = new byte[1024];
while(true) {
bytes_read = source.read(buffer);
if (bytes_read == -1) break;
destination.write(buffer, 0, bytes_read);
}
}
// No matter what happens, always close any streams we've opened.
finally {
if (source != null)
try { source.close(); } catch (IOException e) { ; }
if (destination != null)
try { destination.close(); } catch (IOException e) { ; }
}
}

// File.getParent() can return null when the file is specified without
// a directory or is in the root directory.
// This method handles those cases.
private static File parent(File f) {
String dirname = f.getParent();
if (dirname == null) {
if (f.isAbsolute()) return new File(File.separator);
else return new File(System.getProperty("user.dir"));
}
return new File(dirname);
}

} // fin class
class FileCopyException extends IOException {
public FileCopyException(String msg) { super(msg); }
}
  #2 (permalink)  
Antiguo 28/03/2007, 10:17
Avatar de elAntonie  
Fecha de Ingreso: febrero-2007
Mensajes: 894
Antigüedad: 17 años, 3 meses
Puntos: 10
Re: cómo compilar un archivo

Wenas

Necesitas bajarte la jdk de java para compilarlo. Una vez la tengas instalada usas el comando javac para compilar tu fichero.

Aqui tienes mas informacion.

http://java.sun.com

De todos modos, en google, busca compilar java y te saldran cantidad de ejemplos en cristiano.

Un saludo.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:38.