本文整理汇总了Java中org.codehaus.plexus.util.FileUtils.getExtension方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.getExtension方法的具体用法?Java FileUtils.getExtension怎么用?Java FileUtils.getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.plexus.util.FileUtils
的用法示例。
在下文中一共展示了FileUtils.getExtension方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtension
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
private String getExtension(File artifact, Gav gav) {
if (gav != null && StringUtils.isNotBlank(gav.getExtension())) {
return gav.getExtension();
}
// last resort, the extension of the file
String artifactFileName = artifact.getName().toLowerCase();
// tar.gz? and other "special" combinations
if (artifactFileName.endsWith("tar.gz")) {
return "tar.gz";
} else if (artifactFileName.equals("tar.bz2")) {
return "tar.bz2";
}
// get the part after the last dot
return FileUtils.getExtension(artifactFileName);
}
示例2: getFileNameWithoutExtension
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
* Returns the name of the file without the extension. e.g. if the name is "sample-test.fhx" this would return "sample-test".
*
* @return filename with no extension
*/
public String getFileNameWithoutExtension() {
String ext = "." + FileUtils.getExtension(this.getName());
return this.getName().substring(0, this.getName().length() - ext.length());
}
示例3: getFileFromSaveDialog
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
* Open a JFileChooser and return the file that the user specified for saving. Takes a parameter that specifies the type of file. Either
* TAB or PNG.
*
* @return
*/
private File getFileFromSaveDialog(String fileTypeToSave) {
String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
JFileChooser fc = new JFileChooser(lastVisitedFolder);
File outputFile;
if (fileTypeToSave == "TAB")
{
TABFilter filterTAB = new TABFilter();
fc.addChoosableFileFilter(filterTAB);
fc.setFileFilter(filterTAB);
fc.setDialogTitle("Export table as text file...");
}
else if (fileTypeToSave == "PDF")
{
PDFFilter filterPDF = new PDFFilter();
fc.addChoosableFileFilter(filterPDF);
fc.setFileFilter(filterPDF);
fc.setDialogTitle("Export chart as PDF...");
}
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
outputFile = fc.getSelectedFile();
if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "")
{
log.debug("Output file extension not set by user");
if (fc.getFileFilter().getDescription().equals(new CSVFileFilter().getDescription()))
{
log.debug("Adding csv extension to output file name");
outputFile = new File(outputFile.getAbsolutePath() + ".csv");
}
else if (fc.getFileFilter().getDescription().equals(new PDFFilter().getDescription()))
{
log.debug("Adding pdf extension to output file name");
outputFile = new File(outputFile.getAbsolutePath() + ".pdf");
}
}
else
{
log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
}
App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
}
else
{
return null;
}
if (outputFile.exists())
{
Object[] options = { "Overwrite", "No", "Cancel" };
// notes about parameters: null (don't use custom icon), options (the titles of buttons), options[0] (default button title)
int response = JOptionPane.showOptionDialog(App.mainFrame, "The file '" + outputFile.getName()
+ "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (response != JOptionPane.YES_OPTION)
return null;
}
return outputFile;
}
示例4: getOutputFile
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
* Prompt the user for an output filename
*
* @param filter
* @return
*/
public static File getOutputFile() {
String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
File outputFile;
CSVFileFilter csvff = new CSVFileFilter();
TXTFileFilter txtff = new TXTFileFilter();
// Create a file chooser
final JFileChooser fc = new JFileChooser(lastVisitedFolder);
fc.setAcceptAllFileFilterUsed(true);
fc.addChoosableFileFilter(csvff);
fc.addChoosableFileFilter(txtff);
fc.setFileFilter(csvff);
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setDialogTitle("Save as...");
// In response to a button click:
int returnVal = fc.showSaveDialog(App.mainFrame);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
outputFile = fc.getSelectedFile();
if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "")
{
log.debug("Output file extension not set by user");
if (fc.getFileFilter().getDescription().equals(new TXTFileFilter().getDescription()))
{
log.debug("Adding txt extension to output file name");
outputFile = new File(outputFile.getAbsolutePath() + ".txt");
}
else if (fc.getFileFilter().getDescription().equals(new CSVFileFilter().getDescription()))
{
log.debug("Adding csv extension to output file name");
outputFile = new File(outputFile.getAbsolutePath() + ".csv");
}
}
else
{
log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
}
App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
}
else
{
return null;
}
if (outputFile.exists())
{
Object[] options = { "Overwrite", "No", "Cancel" };
int response = JOptionPane.showOptionDialog(parent, "The file '" + outputFile.getName()
+ "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
options, // the titles of buttons
options[0]); // default button title
if (response != JOptionPane.YES_OPTION)
{
return null;
}
}
return outputFile;
}
示例5: getOutputFile
import org.codehaus.plexus.util.FileUtils; //导入方法依赖的package包/类
/**
* Prompt the user for an output filename
*
* @param filter
* @return
*/
private File getOutputFile(FileFilter filter) {
String lastVisitedFolder = App.prefs.getPref(PrefKey.PREF_LAST_EXPORT_FOLDER, null);
File outputFile;
// Create a file chooser
final JFileChooser fc = new JFileChooser(lastVisitedFolder);
fc.setAcceptAllFileFilterUsed(true);
if (filter != null)
{
fc.addChoosableFileFilter(filter);
fc.setFileFilter(filter);
}
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
fc.setDialogTitle("Save as...");
// In response to a button click:
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
outputFile = fc.getSelectedFile();
if (FileUtils.getExtension(outputFile.getAbsolutePath()) == "")
{
log.debug("Output file extension not set by user");
if (fc.getFileFilter().getDescription().equals(new SHPFileFilter().getDescription()))
{
log.debug("Adding shp extension to output file name");
outputFile = new File(outputFile.getAbsolutePath() + ".shp");
}
}
else
{
log.debug("Output file extension set my user to '" + FileUtils.getExtension(outputFile.getAbsolutePath()) + "'");
}
App.prefs.setPref(PrefKey.PREF_LAST_EXPORT_FOLDER, outputFile.getAbsolutePath());
}
else
{
return null;
}
if (outputFile.exists())
{
Object[] options = { "Overwrite", "No", "Cancel" };
int response = JOptionPane.showOptionDialog(this, "The file '" + outputFile.getName()
+ "' already exists. Are you sure you want to overwrite?", "Confirm", JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, // do not use a custom Icon
options, // the titles of buttons
options[0]); // default button title
if (response != JOptionPane.YES_OPTION)
{
return null;
}
}
return outputFile;
}