我正在做一个电话簿,我想将联系人保存到vcard。我在互联网上找到vcard格式,但是我不知道如何从stdin中读取数据。
package homework;
import java.io.*;
public class SaveToVcard {
public static void vcard() throws IOException {
File file = new File("contact.vcf");
FileOutputStream fop = new FileOutputStream(file);
if (file.exists()) {
String vcard = "BEGIN:VCARD\n" + "VERSION:4.0\n" + "N:Gump;Forrest;;;\n" + "FN:Forrest Gump\n"
+ "ORG:Bubba Gump Shrimp Co.\n" + "TITLE:Shrimp Man\n"
+ "TEL;TYPE=work,voice;VALUE=uri:tel:+1-111-555-1212\n"
+ "TEL;TYPE=home,voice;VALUE=uri:tel:+1-404-555-1212\n" + "EMAIL:forrestgump@example.com\n"
+ "REV:20080424T195243Z\n" + "END:VCARD";
fop.write(vcard.getBytes());
BufferedReader br = null;
String currentLine;
br = new BufferedReader(new FileReader("contact.vcf"));
while ((currentLine = br.readLine()) != null) {
System.out.println(currentLine);
}
fop.flush();
fop.close();
System.out.println("Kész");
} else
System.out.println("A fájl nem létezik");
}
答案 0 :(得分:0)
您可以使用Scanner并执行类似的操作
<div class="card">
<h5 class="card-header">My Cart</h5>
<div class="card-body">
<?php
if(isset($_SESSION['shopping_cart']) && count($_SESSION['shopping_cart']) > 0)
{
$entertainment = $_SESSION['shopping_cart'];
echo '
<table class="table table-hover table-bordered">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Title</th>
<th scope="col">Quantity</th>
<th scope="col">Price</th>
<th scope="col" width="100">Action</th>
</tr>
</thead>';
$item_number = 1;
$total = 0;
foreach ($entertainment as $product) {
echo '
<tbody>
<tr>
<th scope="row">'. $item_number .'</th>
<td>' . $product['title'] . '</td>
<td>'.$product['quantity'].'</td>
<td>$ '. $product['offer_price_corporate_artist']. '</td>
<td>
<a href="cart.php?id_to_remove=' . $item_number . '" class="btn btn-danger btn-sm">X</a>
</td>
</tr>
</tbody>
';
$total += ($product['offer_price_corporate_artist'] * $product['quantity']);
$item_number++;
}
echo '
<tr>
<th colspan="4" align="right">
Total:
</th>
<td>
$ '. $total .'
</td>
</tr>
</table>';
}
else {
echo '<div class="alert alert-primary" role="alert">
Shopping cart is empty, visit <a href="index.php" class="alert-link">products</a> page to add product into shopping cart.
</div>';
}
?>
或者也许可以在运行应用程序时将所需的内容作为参数传递
请参见https://docs.oracle.com/javase/8/docs/api/java/util/Scanner.html