import net.sourceforge.tess4j.Tesseract; import net.sourceforge.tess4j.TesseractException; import java.io.File; public class ImageTextExtractor { public static String extractTextFromImage(String imagePath) { File imageFile = new File(imagePath); Tesseract tesseract = new Tesseract(); try { tesseract.setLanguage("eng"); String result = tesseract.doOCR(imageFile); return result; } catch (TesseractException e) { e.printStackTrace(); return null; } } public static void main(String[] args) { String imagePath = "C:\\Users\\w\\Pictures\\Saved Pictures\\中华人民共和国万岁.jpg"; String extractedText = extractTextFromImage(imagePath); System.out.println(extractedText); } }