Take a network file in java

1

I was able to open a file and put it in a Jlabel on the machine where I'm developing. But when I put the application on the network the machine that is on the network, it does not find the file. Is it possible to get the file from a networked machine? My code is as follows and works perfectly on my machine I'm developing.

String figura = jtResultadoPesquisa.getValueAt(jtResultadoPesquisa.getSelectedRow(), 0).toString(); // quardo o nome do arquivo na figura

String caminho = new File("/home/Pictures/").getCanonicalPath(); // pego o diretorio onde esta o arquivo

ResultadoCaminhoFigura = caminho +"/"+ figura; // tenho o caminho com a figura

ImageIcon img = new ImageIcon (ResultadoCaminhoFigura); //crio uma instancia e coloco a figura e diretorio onde ela se localiza
img.setImage(img.getImage().getScaledInstance(300, 430, 100));

jlVisualisarimagem.setIcon(img); // e seto a figura em um jlabel para ser visualizada.
jlVisualisarimagem.setHorizontalAlignment(JLabel.CENTER);
jspVisualizarimagem.getViewport().add(jlVisualisarimagem);

I've put the comments just to make it easier to understand. When I squeeze in my machine it works cool, but when I put the application on the network it does not bring the image. can anybody help me? Hugs to all.

    
asked by anonymous 05.07.2017 / 22:49

1 answer

1

Although your question is wide, you should not be able to access the picture because that path is local (your computer's own):

String caminho = new File("/home/Pictures/").getCanonicalPath();

When you run the program on other machines, they look in their own directory, not on your computer (where the required image is). One way they access your computer to fetch the image is through IP. For example:

String caminho = new File("172.168.1.50/home/Pictures/").getCanonicalPath();

Where 172.168.1.50 is the IP address of your computer. Of course you will need the necessary access permissions to read the image, among other settings. Remember that this is just an example of access for networked computers.

    
07.07.2017 / 22:44