我想寫一個小程序,將使用掃描儀來檢查是否有下一行(在一段時間的循環),然後也許另一個檢查,在線上的話是標籤APPART並有3串(使用構造函數來創建一個對象),使三根弦將產品名稱廠商Brcodejava掃描儀檢測3個字在線
EG:Tyre17x60固特異458765464
誰誰
我有點堅持這個,所以任何幫助將不勝感激
我想寫一個小程序,將使用掃描儀來檢查是否有下一行(在一段時間的循環),然後也許另一個檢查,在線上的話是標籤APPART並有3串(使用構造函數來創建一個對象),使三根弦將產品名稱廠商Brcodejava掃描儀檢測3個字在線
EG:Tyre17x60固特異458765464
誰誰
我有點堅持這個,所以任何幫助將不勝感激
你可以試試這個:
public static void main (String[] args) throws java.lang.Exception
{
String str = "Tyre17x60 Goodyear 458765464";
InputStream is = new ByteArrayInputStream(str.getBytes());
Scanner sc = new Scanner(is);
sc.useDelimiter("\n");
while (sc.hasNext())
{
String[] tmp = sc.next().split("\t");
if (tmp.length == 3)
System.out.println("Text contains 3 parts separated with tabs");
else
System.out.println("Text is not well formated");
// save data
//productName = tmp[0];
//manufacturer = tmp[1];
//brcode = tmp[2];
}
}
感謝作品完美! – thepolishboy 2013-04-29 12:44:40
假設你從文件中讀取,你可以使用下面的代碼:
Scanner s = new Scanner(new File("file.txt"));
while(s.hasNext())
{
String productName = s.next();
String Manufacturer = s.next();
String Brcode = s.next();
}
如果您有100個產品的文件,並且其中一個缺少條碼,那麼產品的名稱將被讀取,然後整個事情就沒有意義了! – thepolishboy 2013-04-29 12:36:42
Scanner scan = new Scanner("file.txt");
while(scan.hasNext()){
scan.nextLine();
System.out.println("Product : " + scan.next());
System.out.println("Name : " + scan.next());
System.out.println("Code : " + scan.nextLong());
}
嘗試是這樣的....
帖子你的代碼..我們無法讀懂頭腦。 – Maroun 2013-04-29 12:04:59
這樣做的確切問題是什麼?你有什麼試過的? – Kai 2013-04-29 12:05:04