質問
jpgファイルの作成日を抽出したいと考えています。Java には File オブジェクトの lastModified メソッドがありますが、ファイルからの作成日の抽出はサポートされていないようです。Win XP でファイル上にマウス ポインタを置いたときに表示される日付は、DOS でファイルに "dir /TC" を指定して JNI を使用して取得できる日付とは異なるため、情報はファイル内に保存されていると思います。
他のヒント
私はこのメタデータ ライブラリを使用します。 http://www.drewnoakes.com/code/exif/
かなりうまく機能しているようですが、すべての JPEG 画像にこの情報が含まれているわけではないため、100% 確実というわけにはいかないことに注意してください。
EXIF メタデータに作成日が含まれていない場合は、Runtime.exec(...) やシステム関数を使用して確認する必要がない限り、おそらく Java の lastUpdated を使用する必要があります (私ならそうしません)ただし、これはお勧めしません!)
以下のコード例では、ユーザーにファイル パスを要求し、作成日時を出力します。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(final String[] args) {
try {
// get runtime environment and execute child process
Runtime systemShell = Runtime.getRuntime();
BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter filename: ");
String fname=(String)br1.readLine();
Process output = systemShell.exec("cmd /c dir /a "+fname);
// open reader to get output from process
BufferedReader br = new BufferedReader (new InputStreamReader(output.getInputStream()));
String out="";
String line = null;
int step=1;
while((line = br.readLine()) != null )
{
if(step==6)
{
out=line;
}
step++;
} // display process output
try{
out=out.replaceAll(" ","");
System.out.println("CreationDate: "+out.substring(0,10));
System.out.println("CreationTime: "+out.substring(10,15));
}
catch(StringIndexOutOfBoundsException se)
{
System.out.println("File not found");
}
}
catch (IOException ioe){ System.err.println(ioe); }
catch (Throwable t) { t.printStackTrace();}
}
}
所属していません StackOverflow