2015-07-20 64 views

回答

1

這是讀取doc文件並獲取文本的代碼。讀完後全部取決於你想要對文本做什麼。

String extPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.Separator; 
    AssetManager assetManager= getApplicationContext().getAssets(); 
    InputStream inputStream = assetManager.open(extPath + "file.doc"); 
    String text = loadFile(inputStream); 

的方法的loadFile是---

public String loadFile(InputStream inputStream){ 
    ByteArrayOutputStream b = new ByteArrayOutputStream(); 
    byte[] bytes = new byte[4096]; 
    int length = 0; 
     while(){ 
     b.write(bytes, 0, length); 
     } 
    return new String(b.toByteArray(), "UTF8"); 
    }