我试过这些方法来查找文件的MIME类型......
Path source = Paths
.get("C://Users/akash/Desktop/FW Internal release of MSTClient-Server5.02.04_24.msg");
System.out.println(Files.probeContentType(source));
Run Code Online (Sandbox Code Playgroud)
上面的代码返回 null...
如果我使用Apache的TIKA API来获取MIME类型,那么它将它作为text/plain ...
但我希望结果如此 application/vnd.ms-outlook
UPDATE
我也使用MIME-Util.jar如下代码...
MimeUtil2 mimeUtil = new MimeUtil2();
mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
RandomAccessFile file1 = new RandomAccessFile(
"C://Users/akash/Desktop/FW Internal release of MSTClient-Server5.02.04_24.msg",
"r");
System.out.println(file1.length());
byte[] file = new byte[624128];
file1.read(file, 0, 624128);
String mimeType = MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(file)).toString();
Run Code Online (Sandbox Code Playgroud)
这给了我输出 application/msword
更新:
Tika API超出了范围,因为它太大而无法包含在项目中......
那么如何找到MIME类型?
我搜索了这个,但找不到我需要的东西,所以我创建了一个新帖子.我希望了解这个问题.谢谢.
ArrayList<String> arraylist= new ArrayList<String>();
arraylist.add("Nguyen");
arraylist.add("Viet");
String[] name={"Quan","Doan","Thi","Ha"};
arraylist.add(name);// error here
ArrayList<Object> arraylist1=new ArrayList<Object>();
arraylist1.add("Nguyen");
arraylist1.add("Viet");
Object[] name1={"Quan","Doan","Thi","Ha"};
arraylist1.add(name1);// not error
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下,当我name进入add()方法然后我得到一个错误,但当我name1进入add()方法,它工作正常,为什么会这样...
我是java的初学者.我想首先检查用户输入是String还是Double或int.如果是String,double或减号,则应提示用户再次输入有效的int号.只有当用户输入有效数字时,程序才会跳转尝试.我一直在想几个小时,我没有任何用处.请帮助,谢谢!
import java.util.InputMismatchException;
import java.util.Scanner;
public class Fizz {
public static void main(String[] args) {
System.out.println("Please enter a number");
Scanner scan = new Scanner(System.in);
try {
Integer i = scan.nextInt();
if (i % 3 == 0 && (i % 5 == 0)) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(i + "?3?5???????????");
}
} catch (InputMismatchException e) {
System.out.println("");
} finally { …Run Code Online (Sandbox Code Playgroud) 我试过下面的代码......没有任何运气......
private void updateFile(Drive service, String fileId) {
try {
File file = new File(); /********/
final java.io.File fileToUpdate = new java.io.File("D:/Work Data/Files/pdf.pdf");
FileContent mediaContent = new FileContent("image/pdf", fileToUpdate);
file = service.files().update(fileId, file, mediaContent).execute();
System.out.println(fileId);
} catch (Exception e) {
if (isDebug) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
也试过...
private void updateFile(Drive service, String fileId) {
try {
File file = service.files().get(fileId).execute(); /********/
final java.io.File fileToUpdate = new java.io.File("D:/Work Data/Files/pdf.pdf");
FileContent mediaContent = new FileContent("image/pdf", fileToUpdate);
file = service.files().update(fileId, file, mediaContent).execute(); …Run Code Online (Sandbox Code Playgroud) interface Vehicle
{
public abstract void getVehicle();
}
public class HelloWorld implements Vehicle{
@Override
public void getVehicle()
{
System.out.println("HelloWorld Implementation");
}
}
class MyWorld extends HelloWorld implements Vehicle
{
@Override
public void getVehicle()
{
System.out.println("MyWorld Implementation");
}
}
Run Code Online (Sandbox Code Playgroud)
当两个类都在实现抽象方法时getVehicle(),这里实际发生了什么?子类是否重写超类getvehicle()或Inteface getVehicle()?
我只是想知道如何从一个内容页面移动到另一个内容页面.请查看elseif()代码.我必须在该块中编写,以便我可以移动到另一个内容页面(命名为MainView). CS)..
button.Clicked += (sender, e) =>
{
if (String.IsNullOrEmpty(username.Text) || String.IsNullOrEmpty(password.Text))
{
DisplayAlert("Oops!!Validation Error", "Username and Password are required", "Re-try");
}
else if (username.Text == "kanak" && password.Text == "1234")
{
// your code here
}
else
{
DisplayAlert("Failed", "Invalid User", "Login Again");
}
};
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏..
问题:
我希望所有1-50的数字都不能被7整除,但也没有7中的数字,比如17,27等.下面的代码可以工作但(i-10)%7必须从头开始i=6.现在它认为数字3不计算原因(3-10)=-7是0 mod 7.如何在if语句中解决这个问题?
for(int i=1; i<=50;i++){
if(i%7!=0 && (i-10)%7!=0){
System.out.println(i);
Run Code Online (Sandbox Code Playgroud) 这是我直接从“Head First Java”获得的来源,但无论我做什么,我似乎都无法使其工作,而且我不知道我可能会错过什么
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleGui3C implements ActionListener {
JFrame frame;
public static void main(String[] args) {
SimpleGui3C gui = new SimpleGui3C();
gui.go();
}
public void go() {
MyDrawPanel drawPanel = new MyDrawPanel();
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("Change colors");
button.addActionListener(this);
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
frame.setSize(300, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
frame.repaint();
}
}
class MyDrawPanel extends JPanel {
public void paintComponent(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, …Run Code Online (Sandbox Code Playgroud) 我想把主线程作为守护程序线程,但它告诉我IllegalThreadStateException.有没有办法做到这一点?
public class DeamonThreads {
public static void main(String[] args) {
System.out.println("Main Started");
System.out.println("Thread type deamon = " + Thread.currentThread().isDaemon());
Thread.currentThread().setDaemon(true);
System.out.println("Thread type deamon = " + Thread.currentThread().isDaemon());
System.out.println("Main End");
}
}
Output
Main Started
Thread type deamon = false
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.setDaemon(Thread.java:1367)
at com.threads.DeamonThreads.main(DeamonThreads.java:8)
Run Code Online (Sandbox Code Playgroud)