使用Java识别文件扩展名 [英] identify the file extension using java
问题描述
我在数据库中有不同的格式文件.我想复制到我的本地计算机上.
i have different format files in DB. i want to copy to my local machine.
我如何识别文件格式(doc,xls等...)
how can i identify the file format (doc, xls, etc...)
关于,克里希纳
感谢您提供建议...根据您的建议,我编写了代码&我完成了...
Thanks, for providing suggestions... based on your suggestions i had written the code & i am completed...
请查看我的博客..我在此处发布了代码...
please look into my blog.. i posted the code over here...
http://muralie39.wordpress.com/java-program-to-copy-files-from-oracle-to-localhost/
谢谢你们.
谢谢,克里希纳
推荐答案
如果文件是按照约定命名的,则只需解析文件名即可:
If your files are named according to convention, you can just parse the filename:
String filename = "yourFileName";
int dotPosition = filename.lastIndexOf(".");
String extension = "";
if (dotPosition != -1) {
extension = filename.substring(dotPosition);
}
System.out.println("The file is of type: " + extension);
这是最简单的方法,假设您的文件是使用某种标准命名约定来命名的.扩展可能是您系统专有的,即使它们遵循约定也可以使用.
That's the simplest approach, assuming your files are named using some kind of standard naming convention. The extensions could be proprietary to your system, even, as long as they follow a convention this will work.
如果您需要实际扫描文件以获取格式信息,则需要对文档格式进行更多调查.
If you need to actually scan the file to get the format information, you will need to do some more investigation into document formats.
这篇关于使用Java识别文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!