我想在msbuild中检查文件是否存在且不为空。我该怎么做
答案 0 :(得分:1)
您可以使用import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
public class DateSpinner {
private JComponent ui = null;
DateSpinner() {
initUI();
}
public void initUI() {
if (ui!=null) return;
ui = new JPanel(new BorderLayout(4,4));
ui.setBorder(new EmptyBorder(100,100,100,100));
JButton dateSelector = new JButton("Select a date (after now)");
ActionListener dateSelectorListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SpinnerDateModel spinnerDateModel = new SpinnerDateModel();
JSpinner spinner = new JSpinner(spinnerDateModel);
JOptionPane.showMessageDialog(
ui, spinner, "Choose Date", JOptionPane.QUESTION_MESSAGE);
System.out.println("Date Chosen: " + spinnerDateModel.getDate());
}
};
dateSelector.addActionListener(dateSelectorListener);
ui.add(dateSelector);
}
public JComponent getUI() {
return ui;
}
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception useDefault) {
}
DateSpinner o = new DateSpinner();
JFrame f = new JFrame(o.getClass().getSimpleName());
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setLocationByPlatform(true);
f.setContentPane(o.getUI());
f.pack();
f.setMinimumSize(f.getSize());
f.setVisible(true);
}
};
SwingUtilities.invokeLater(r);
}
}
和Exists
来获取文件的内容。
ReadAllText