Alguem pode me ajudar

Preciso abrir um arquivo,mas o usuario ira entrar com o diretorio,pasta e o nome do arquivo…como faco isso??
Esse é um pedaco do codigo

1 System.out.println(“Complete File Directory:”);//
2 try {
3 bytelidos = System.in.read(vetortext);//*
4 File in = new File(“G:/tiago/Java/JavaProjects/array4/classes/Nutz_Esri.flt”

Na linha 4,ao invez de colocar o caminho de onde esta o arquivo,quero que o usuario faca isso,assim nao preciso ficar mudadndo o codigo toda hora…
Se alguem puder me ajudar…Obrigado
Tiago

[quote=“laine”]Preciso abrir um arquivo,mas o usuario ira entrar com o diretorio,pasta e o nome do arquivo…como faco isso??
Esse é um pedaco do codigo

1 System.out.println(“Complete File Directory:”);//
2 try {
3 bytelidos = System.in.read(vetortext);//*
4 File in = new File(“G:/tiago/Java/JavaProjects/array4/classes/Nutz_Esri.flt”

Na linha 4,ao invez de colocar o caminho de onde esta o arquivo,quero que o usuario faca isso,assim nao preciso ficar mudadndo o codigo toda hora…
Se alguem puder me ajudar…Obrigado
Tiago[/quote]

Você poderia pegar este caminha de um JTree, ou de um JTextField, onde o usuário especificaria o caminho

Ola,
como faco para pegar,ou usar esse JTree, ou TTextField???

[quote=“laine”]Ola,
como faco para pegar,ou usar esse JTree, ou TTextField???[/quote]

Aí você teria que procurar na Internet… vai no google, vc acha bastante coisa sobre estes dois componentes

Uhm… naõ entendi o problema…que tal:


     String caminho = lerDiretorio();

     System.out.println("Complete File Directory:");//
     try {
         bytelidos = System.in.read(vetortext);//*
         File in = new            File(caminho);

Onde lerDIretorio() pega os dados com o cliente, seja lá de qual maneira você tiver que usar.

[]s

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

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

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 text[] = new byte[200];
byte vetortext[] = new byte[200];
int bytelidos = 0;

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

System.out.println(“Complete File Directory:”);//
try {
bytelidos = System.in.read(vetortext);//*
-> File in = new File(vetortext,0,bytelidos);//*
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 < n_cols; y++) {
  for (int x = 0; x < n_rows; x++) {

      try {
        a = (float)points[x][y];
        System.out.println("Output x : " + x + " ;" + " y : " + y + " ->" +
                           " 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();
}

}
}

Onde indiquei com uma seta,como faco por exemplo,peco pro usuario digitar onde esta o arquivo que ele quer abrir,salvar essa string numa variavel e coloca-la naquela linha onde esta a seta,ou sei la…como faco isso??

Bota o teu código como code para ficar melhor a visualização…

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

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

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 text[] = new byte[200];
byte vetortext[] = new byte[200];
int bytelidos = 0;

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

System.out.println(“Complete File Directory:”);//
try {
bytelidos = System.in.read(vetortext);//*
File in = new File(vetortext,0,bytelidos);//*
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 < n_cols; y++) {
  for (int x = 0; x < n_rows; x++) {

      try {
        a = (float)points[x][y];
        System.out.println("Output x : " + x + " ;" + " y : " + y + " ->" +
                           " 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]

como faco isso?[/code]

teu código

[teste]