Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

If I compile Java app at another location it can not read from any folder

I have an app. Which is in RC state. I've started finalizing works by splitting the classes to separate files with appropriate import sets at another location but suddenly I've found that cleaner version cannot read from any folder. So I investigated that if I compile the code in another location except the actual (original) app cannot read from any folder.

Strange is that from folders from those cannot be read can be obtained path (subdirectories included).

I have packed this app to executable jar file before started this works. Maybe somewhere in JVM is something stuck?

Note: New files are compiled without error. I've tried both original source and new sources.

Failure is in methods File.list() or File.listFiles(). The same using directory stream.

Used packages:

import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.table.DefaultTableModel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import java.io.LineNumberReader;
import java.io.FileReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.DataInputStream;
import java.io.FilenameFilter;

import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.UnsupportedLookAndFeelException;

For sure at this part:

private void loadFiles(){
    cesta=folderPicker.getSelectedFile();       
    if(folder==null||loadedCesta!=cesta||(cesta==folderPicker.getSelectedFile()&vetsiPismoVisible==true)){      
    folder=new File(cesta.getName());       

    String datFiles[]=folder.list(new FilenameFilter() {
public boolean accept(File folder, String fileName) {
    return fileName.endsWith(".dat");}});

If I try: folder.canRead()
on every folder on my PC and also e.g.on my workstation these new compilations get false as a result. Variable: folderPicker is reffering to JFileChooser that is limited to folders and folders are obtained via actionListener of special JButton (not classic Open and Cancel). You can try it from Karolina_RC.jar from link provided in commentary under conditions said.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Problem solved. For some reason is no longer possible to use only folder name to make File type (folder). Now it is required to use path.

E.g.

File folder=new File(path.getName());
File folder=new File(path.getPath());

Former no longer working. Latter does. I am guessing some JVM-compile issue.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...