Abrir pasta compartilhada no linux com o samba

Ola pessoal, estou com o seguinte código e está funcionando normalmente, mas apareceu um problema, preciso que ao invés de abrir os meus documentos ele já acione direto uma unidade compartilhada na rede por um Samba.

Mas até agora não tive ideia nenhuma. :slight_smile:

Eis o código:

import java.io.*; 
import javax.swing.JFileChooser; 
import javax.swing.JFrame;
import javax.swing.JOptionPane; 

/**
   Classe Principal do 
   Editor de Texto Simples 
*/
public class Editor extends JFrame {
	private javax.swing.JPanel jContentPane = null;
	private javax.swing.JPanel jPanel = null;
	private javax.swing.JButton jButton = null;
	private javax.swing.JButton jButton1 = null;
	private javax.swing.JButton jButton2 = null;
	private javax.swing.JScrollPane jScrollPane = null;
	private javax.swing.JTextArea jTextArea = null;
	private javax.swing.JFileChooser jFileChooser = null;
	private boolean hasChanged = false; 
	private static final String title = "Gerar MFD"; 

	/**
	 * Construtor Default
	 */
	public Editor() {
		super(); 
		initialize(); 
	}
   
	private javax.swing.JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new javax.swing.JPanel();
			jContentPane.setLayout(new java.awt.BorderLayout());
			jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH);
			jContentPane.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
			jContentPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
		}
		return jContentPane;
	}

	private void initialize() {
		this.setContentPane(getJContentPane());
		this.setSize(480, 284); 
		this.setTitle(title);
		this.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 
       
		this.addWindowListener(new java.awt.event.WindowAdapter() { 
			public void windowClosing(java.awt.event.WindowEvent e) {
				doExit(); 
			}
		});

	}

		private javax.swing.JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new javax.swing.JPanel();
			jPanel.add(getJButton(), null);
			jPanel.add(getJButton1(), null);
			jPanel.add(getJButton2(), null);
		}
		return jPanel;
	}


	private javax.swing.JButton getJButton() {
		if (jButton == null) {
			jButton = new javax.swing.JButton();
			jButton.setText("Abrir arquivo");
			jButton.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) { 
					loadFile();
				}
			});
		}
		return jButton;
	}


	private javax.swing.JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new javax.swing.JButton();
			jButton1.setText("Salvar arquivo");
			jButton1.addActionListener(new java.awt.event.ActionListener() { 
				public void actionPerformed(java.awt.event.ActionEvent e) {
					saveFile();
				}
			});
		}
		return jButton1;
	}

	private javax.swing.JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new javax.swing.JButton();
			jButton2.setText("Sair");
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					doExit();
				}
			});
		}
		return jButton2;
	}

	private javax.swing.JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new javax.swing.JScrollPane();
			jScrollPane.setViewportView(getJTextArea());
		}
		return jScrollPane;
	}
	private javax.swing.JTextArea getJTextArea() {
		if (jTextArea == null) {
			jTextArea = new javax.swing.JTextArea();
			jTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
				public void keyTyped(java.awt.event.KeyEvent e) {
					if (!hasChanged) {
						setTitle(title + " *");
						hasChanged = true;
					}
				}
			});
		}
		return jTextArea;
	}

	private javax.swing.JFileChooser getJFileChooser() {
		if (jFileChooser == null) {
			jFileChooser = new javax.swing.JFileChooser();
			jFileChooser.setMultiSelectionEnabled(false);
		}
		return jFileChooser;
	}

  	private void loadFile() {
		int state = getJFileChooser().showOpenDialog(this); 
		if (state == JFileChooser.APPROVE_OPTION) { 
			File f = getJFileChooser().getSelectedFile(); 
			try { //Tenta ler o arquivo para o controle de texto
				FileReader fr = new FileReader(f); 
            String temp = ""; 
           
            int i = fr.read(); 
            while (i!=-1) {
               temp+=((char)i); 
               i = fr.read();
            } 
            fr.close(); 
            getJTextArea().setText(temp); 
				setTitle(title); 
				hasChanged = false;
			} catch (FileNotFoundException e) { 
				e.printStackTrace();
			} catch (IOException e) { 
			}
		}
	}

   
	private void saveFile() {
		int state = getJFileChooser().showSaveDialog(this); 
		if (state == JFileChooser.APPROVE_OPTION) { 
			File f = getJFileChooser().getSelectedFile(); 
			try {
            
				FileWriter fw = new FileWriter(f);
            
            
            
            fw.write(getJTextArea().getText());
            fw.close();//fecha arquivo
				setTitle(title); 
				hasChanged = false;
			} catch (FileNotFoundException e) { 
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

   	private void doExit() {
		if (hasChanged) {
			int state = JOptionPane.showConfirmDialog(this,
					"O Arquivo foi moficado. Quer salva antes de sair?");
			if (state == JOptionPane.YES_OPTION) {
				saveFile();
			} else if (state == JOptionPane.CANCEL_OPTION) {
				return;
			}
		}
		System.exit(0);
	}
   
  
   public static void main(String[] args) {
      javax.swing.SwingUtilities.invokeLater(new Runnable() { 
            public void run() {
                Editor e = new Editor(); 
                e.setVisible(true); 
            }
        });
      
   }
   
   
} 

Dê uma olhadinha no que você já escreveu.

            jFileChooser = new javax.swing.JFileChooser();  
            jFileChooser.setMultiSelectionEnabled(false);  

Você pode adicionar mais chamadas a métodos do JFileChooser de modo que ele já comece em um diretório configurado na sua aplicação :slight_smile:
Você tem de fazer isso antes de abrir o JFileChooser.

Referência:
JFileChooser.setCurrentDirectory

Atenção - “File” é java.io.File, ou seja, uma representação de um pathname (pode ser um nome de diretório !)

Dica: Sempre olhe no Javadoc antes de mais nada. Só de você olhar que existem N métodos já ajuda você a procurar no Google.