Alguem pode me ajudar

Qual programa você está utilizando ?

JBuilderX

Tem um menu em algum lugar que se chama arguments ou parameters, não me lembro se está dentro de builder ou de outro menu, nele você passa o diretório do seu arquivo.

Você também pode testar no DOS. Acredito que seu usuário não vai utilizar o JBuilder.

Falow
:slight_smile:

Blz…vo tentar achar algo

public static String entradaTeclado() throws IOException
	{
		int i = 0;
		String s = "";
		
		BufferedInputStream bis;
		
		do
		{	
			System.out.println( "Digitando o nome do Arquivo: ");
			System.out.println("Ex.: C:\nome_diretorio\nomearquivo";

			bis = new BufferedInputStream(System.in);
			
			while((i = bis.read()) != 10 )
			{
				s += (char) i;
			}
			
			if(i == 10)
			{
				System.out.println( "Nao foi digitado nada" );
				return s;
			}	
			
		}while(i != -1 || i != 10);
		
	
		return s;
	}

GELO_SP[quote][/quote]

O Rogerio,
num entendi isso ai naum,acho que essas linhas nao sao o que to procurando.
Quero que o usuario digite o endereco do arquivo e preciso acessar essa variavel com o caminho do arquivo, e abrir o arquivo atraves dela…como faco isso?
O programa esta em fase de montagem,prototipo,entao nao vou montar interface grafica com o usuario ainda,quero que ele digite o endereco naquela janela de erros,onde eles aparecem ao compilar o programa.To usando o JBuilderX.
Espero resposta…
Obrigado

Bom… C ainda nao tem interface grafica pq vc nao faz assim:

[code]public class Blablabla{

  public static void main(String args[]){
       new Blablabla(args[0]);
  }

  public Blablabla(String caminho){
      File file = new File(caminho);
  }

}
[/code]

entao, pro usuario passar o caminho do arquivo ele roda via prompt assim:

java Blablabla "caminho do arquivo"

O Alexandre…
num sei onde plicar isso no meu programa…vc pode me ajudar a modificar o programa…pq nao to conseguindo!!!
Obrigado

Onde esta seu programa ??

O programa ta ai…tem uma linha onde ta escrito:
G:/tiago/Java/JavaProjects/array4/classes/Nutz_Esri.flt
isso dai tem que cair fora,pois o usuario é que vai selecionar o arquivo…
da um a olhada ai e ve o que tenho que fazer…se vc pode me ajudar.
Obrigado

[import java.io.;
import java.util.
;

public class array4 {
BufferedReader inReader;//hdr
PrintWriter outWriter;//hdr
String line;//hdr

private String[] args;

public array4 () //constructor
{
BufferedReader inReader = null;
PrintWriter outWriter = null;
}

public static void main(String[] args) {

array4 f = new array4();
f.readMyFile();

}

void readMyFile() {
array4 f = new array4();
DataInputStream data = null; //Variables
DataOutputStream data2 = null;
String record = null;
int recCount = 0;
int n_rows, n_cols;
int c;
double dummy;
n_rows = 179; //x
n_cols = 254; //y
double[][] points = new double[n_rows][n_cols]; //2D Array
float a; //receive datas from 2D Arry
byte T[] = new byte[200];
byte vetortext[] = new byte[200];
int bytelidos = 0;

String t;
String line = null,lineTokens;//hdr
int H_ncols;//hdr
int H_nrows;//hdr
double H_XCorner;//hdr
double H_YCorner;//hdr
int H_CellSize;//hdr
String H_Byteorder;//hdr
double H_Nodatavalue;//hdr

try {File in = new File(“G:/tiago/Java/JavaProjects/array4/classes/Nutz_Esri.flt”);
FileInputStream fis = new FileInputStream(in);
BufferedInputStream bis = new BufferedInputStream(fis);
data = new DataInputStream(bis);
for (int y = 0; y < n_cols; y++) {
for (int x = 0; x < n_rows; x++) {
try {
points[x][y] = (double) data.readFloat();
System.out.println(“Input x : " + x + " ;” + " y : " + y + " ->" +
" Value : " + (float)points[x][y]);
}
catch (EOFException e) {
// catch EOF occuring while reading
System.out.println("ACHTUNG,got an EOFException error! " +
e.getMessage());
}
}
}
}

catch (IOException e) {
  // catch io errors from FileInputStream or readLine()
  System.out.println("ACHTUNG, got an IOException error! " + e.getMessage());
}
finally {
  // if the file opened okay, make sure we close it
  if (data != null) {
    try {
      data.close();
    }
    catch
        (IOException ioe) {
    }
  }
}

File out = new File("G:/tiago/Java/JavaProjects/array4/classes/copy2.bin"); //copy-out
FileOutputStream fos = null;
try {
  fos = new FileOutputStream(out);
}
catch (FileNotFoundException ex) {
}
BufferedOutputStream bos = new BufferedOutputStream(fos);

data2 = new DataOutputStream(bos);

try {
  FileWriter saida = new FileWriter(out);
}
catch (IOException ex1) {
  System.out.println("Achtung,problems with creating the output file " +  ex1.getMessage());
}

for (int y = 0; y &lt; n_cols; y++) {
  for (int x = 0; x &lt; n_rows; x++) {

      try {
        a = (float)points[x][y];
        System.out.println("Output x : " + x + " ;" + " y : " + y + " -&gt;" +
                           " Value : " + a);
        data2.writeFloat(a);

      }
      catch (IOException ioe) {
        System.out.println("Achtung,problems with writing data" + ioe.getMessage());

    }
  }

}try{
  data2.close();
}catch(IOException e) {
e.getMessage();
}

}
}
][/code]

a alternativa do aborges já foi postada anteriormente pelo dgouvea.

Para utilizar esta opção, como vc disse ainda estar em uma fase de prototipação e não julga necessária a interação com o usuário, pode passar o nome do arquivo como parâmetro na hora de executar a classe, rodando via DOS, por exemplo. Ou como já foi citado, dá uma olhada onde na sua ferramenta pode passar os parâmetros para a classe

Para colocar seu codigo identado digite como se segue as linhas abaixo:

clique duas vezes em Code e enter os dois Codes que aparecerem vc coloca o seu codigo java.

public static void main(String[] args) throws IOException {
                
         System.out.println( "
Entre com diretorio e o nome do arquivo :" );

	try
	{
	    BufferedReader br = new BufferedReader(
	       new FileReader( System.in ));

                    /* Pega o conteudo digitado*/
                    if( ( s = br.readLine() ) != null)
	    {
	         	System.out.println(s);
                     /* coloque aqui suas interações com codigos internos e externos a classe e/ou metodos*/
	}

	catch(IOException e)
	{
   	    System.out.println( "Arquivo não pode ser encontrado" );
                     System.out.println( e.getMessage() );
	    System.exit(0);			
	}
	br.close();				
    }

O Rogerio, to fazendo o seguinte:
Criei um ainterface grafica com o usuario,mas estou tendo um problema,talvez vc possa me ajudar ao dar uma olhada no codigo…marquei com interrrogacao de onde ate onde estou tendo duvidas…
Obrigado

[import java.io.;
import java.awt.
;
import java.awt.event.;
import javax.swing.
;
import javax.swing.filechooser.*;

/*

  • FileChooserDemo.java is a 1.4 application that uses these files:

  • images/Open16.gif

  • images/Save16.gif
    */
    public class FileChooserDemo extends JPanel
    implements ActionListener {
    static private final String newline = "
    ";
    JButton openButton, saveButton;
    JTextArea log;
    JFileChooser fc;
    BufferedReader inReader = null;
    DataInputStream data = null;
    private InputStream fis;
    public FileChooserDemo() {
    super(new BorderLayout());

    //Create the log first, because the action listeners
    //need to refer to it.
    log = new JTextArea(5,20);
    log.setMargin(new Insets(5,5,5,5));
    log.setEditable(false);
    JScrollPane logScrollPane = new JScrollPane(log);

    //Create a file chooser
    fc = new JFileChooser();

    //Uncomment one of the following lines to try a different
    //file selection mode. The first allows just directories
    //to be selected (and, at least in the Java look and feel,
    //shown). The second allows both files and directories
    //to be selected. If you leave these lines commented out,
    //then the default mode (FILES_ONLY) will be used.
    //
    //fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    //fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    //Create the open button. We use the image from the JLF
    //Graphics Repository (but we extracted it from the jar).
    openButton = new JButton(“Open a File…”,
    createImageIcon(“images/Open16.gif”));
    openButton.addActionListener(this);

    //Create the save button. We use the image from the JLF
    //Graphics Repository (but we extracted it from the jar).
    saveButton = new JButton(“Save a File…”,
    createImageIcon(“images/Save16.gif”));
    saveButton.addActionListener(this);

    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel(); //use FlowLayout
    buttonPanel.add(openButton);
    buttonPanel.add(saveButton);

    //Add the buttons and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(logScrollPane, BorderLayout.CENTER);
    }

public void actionPerformed(ActionEvent e) {

int n_rows = 179;
int n_cols = 254;
double[][] points = new double[n_rows][n_cols];

//Handle open button action.
    if (e.getSource() == openButton) {
        int returnVal = fc.showOpenDialog(FileChooserDemo.this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();

?? //This is where a real application would open the file.
try {
FileInputStream fis = new FileInputStream(file.getName());

                }
            catch (FileNotFoundException ex) {
            }
            BufferedInputStream bis = new BufferedInputStream(fis);
            data = new DataInputStream(bis);
            log.append("Opening: " + file.getName() + "." + newline);
            
            for (int y = 0; y &lt; n_cols; y++) {
               for (int x = 0; x &lt; n_rows; x++)
              {
               
                try{
                  points[x][y] = (double) data.readFloat();
                  log.append("Input x : " + x + " ;" + " y : " + y + " -&gt;" +
                           " Value : " + (float)points[x][y]);
                }catch(IOException a) {
??                log.append("Open command ERROR." + newline);
                }

                }][/code]

Laine,

evite duplicar mensagens em tópicos diferentes. Por isso eu apaguei o seu último tópico criado, ok?

[]s

p.s.: acho que todos os seus problemas poderiam ser resolvidos com uma rápida consulta à documentação da API: http://java.sun.com/j2se/1.4.2/docs/api/

Ola galera,
essa é uma parte do codigo,que to fazendo,mas ta dando um erro…seguinte:
o programa roda blz ate a linha 100,onde marquei,mas dai pra frente ele pula pra linha 105,ele nao compila as linhas intermediarias…eu to fazendo algo errado ali no meio,ou acima da linha 100…alguma passagem de parametro ilegal ou algo do tipo…c puderem me ajudar.
Obrigado

if (e.getSource() == openButton) {
            int returnVal = fc.showOpenDialog(FileChooserDemo.this);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = fc.getSelectedFile();
                //This is where a real application would open the file.
                try {
                  FileInputStream fis = new FileInputStream(file.getName());
                  
                    }
                catch (FileNotFoundException ex) {
                }
                BufferedInputStream bis = new BufferedInputStream(fis);
                data = new DataInputStream(bis);
                log.append("Opening: " + file.getName() + "." + newline);
                
                for (int y = 0; y < n_cols; y++) {
                   for (int x = 0; x < n_rows; x++)
                  {
                   
      100              try{
                      points[x][y] = (double) data.readFloat();
                      log.append("Input x : " + x + " ;" + " y : " + y + " ->" +
                               " Value : " + (float)points[x][y]);
                    }catch(IOException a) {
       105             log.append("Open command ERROR." + newline);
                    }

                    }
                  }

Sem as mensagens de erros jogadas fica meio difícil de descobrir. Mas, chutando, acredito que o comando

log.append("blablabla");

jogue uma java.io.IOException. Por isso, dentro do bloco catch(IOException e) você vai precisar colocar o comando dentro de outro bloco try/catch. Ou então, fazer da maneira mais simples possível:

try{
   //blablablabla
}catch(IOException ioe){
   ioe.printStackTrace(System.err);
}

Por fim, leia este tópico aqui para aprender como reportar erros no GUJ: http://www.guj.com.br/forum/viewtopic.php?t=6096

A mensagem de erro nao é de complicao e sim uma mensagem de erro que criei para o programa.
Parece que ele nao esta encontrando o arquivo para abrir,entendeu?
Vc sugeriu é que eu faca um IOException,mas onde?
Obrigado

[quote=“laine”]Parece que ele nao esta encontrando o arquivo para abrir,entendeu?
[/quote]

Parece ou não está encontrando o arquivo? Sem o stack trace fica difícil ajudá-lo.

O Daniel,
eu sou iniciante em Java,o que é stack trace??
Obrigado

[O erro é o seguinte:
Open command ERROR.
Onde na verdade deveria aparecer algo assim:
Input X:34 , Y:50
Input X:30 , Y:30

e por ai vai…dentro do arquivo tenho coordenadas,numa matriz 2D]
Ficou mais claro agora??
Obrigado[/quote]