MiMa (6) [Avatar] Offline
#1
Hi,
i´m learning Java and Tika.
At this time i work with the book on side 63 to getType.

I had written an Java Class that read file from my Disk and will be detected the type, but it will doesn't work.

Code Start:

import java.io.*;
import java.util.Map;
import org.apache.tika.mime.MediaType;

public class MediaTypErweiterung
{

public static void main(String[] args) throws Exception
{
File path = new File("/Users/michael/Desktop/Screens");
// File path = new File("/Users/michael/Desktop/Tika");
File[] fileList = path.listFiles();
int anzahl = (path.list().length);

// Files From Array
// File file = fileList[7]; // Webloc
// File file = fileList[2]; // JPEG
// File file = fileList[0]; // DS_Store
// File file = fileList[11]; // Windows Icon
// File file = fileList[10]; // Apple Icon
// File file = fileList[12]; // Folder ICON
File file = fileList[15]; // PDF File Path and Name
String fileNamePath = file.toString();
System.out.println(fileNamePath)

MediaType type = MediaType.parse(fileNamePath);

System.out.println("type: " + type.getType());
System.out.println("subtype " + type.getSubtype());

Map<String, String> parameters = type.getParameters();
System.out.println("parameters:");
for (String name : parameters.keySet())
{
System.out.println(" " + name + "=" + parameters.get(name));
}
}
}

Code End:

What i get are follow Error Message:

/Users/michael/Desktop/Screens/Message.pdf
Exception in thread "main" java.lang.NullPointerException
at MediaTypErweiterung.main(MediaTypErweiterung.java:44)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

This is the Line 44
System.out.println("type: " + type.getType());

I dont know what i can do now?

Thanks for Help

Michael
MiMa (6) [Avatar] Offline
#2
Re: Media Type in tika
OK, i found the problem by myself.

Thanks

Michael
chris.mattmann (14) [Avatar] Offline
#3
Re: Media Type in tika
ah glad you found it!