但是这个过程如果你用java自带的文件流格式打开的话,写进去会是乱码。我做过的方法是用开源框架包,poi.jar可以用来做有关office的打开、写入、读出等 *** 作,具体代码没有了,但是demo里面的代码都已经足够了,你自己稍微看看就能知道怎么做了。这个包还是比较稳定的。 求采纳
由于ArrayList是按照保存的顺序排序的 所以删除就是删除最后一个
代码如下:
private final static String[] chineseNumber = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十"}private final static String[] chineseBits = {"十", "百", "千", "万"}
public static addBook(String bookName, int cost, String id, String date) {
books.add(new Book("第" + toChineseNumber(books.length) + "本书", "第" + toChineseNumber(books.length) + "号出版社" ), cost, id, date)
}
public static deleteBook() {
books.remove(books.length - 1)
}
private static toChineseNumber(int source) {
StringBuilder sb = new StringBuilder()
for (int i = 0 i < source.length() i++) {
int n = Integer.valueOf(source.charAt(i))
String chinese = chineseNumber[n]
String bits = chineseBits[source.length() - i - 1]
if(0 == n) {
sb.append(chinese)
} else {
sb.append(chinese + bits)
}
}
}
public class Book {public String name //书名
public String author //作者
public String publisher //出版社
public String state //状态:STATE_IN 在馆 STATE_OUT 外借
public static String STATE_IN = "in"
public static String STATE_OUT = "out"
public Book(String name, String author, String publisher){
this.name = name
this.author = author
this.publisher = publisher
}
public Book(String name, String author, String publisher, String state){
this.name = name
this.author = author
this.publisher = publisher
this.state = state
}
public static void main(String[] args) {
Book book1 = new Book("西游记", "吴承恩", "新华出版社")
book1.setState(STATE_IN)
Book book2 = new Book("水浒传", "施耐庵", "新华出版社", STATE_IN)
}
public String getName() {
return name
}
public void setName(String name) {
this.name = name
}
public String getAuthor() {
return author
}
public void setAuthor(String author) {
this.author = author
}
public String getPublisher() {
return publisher
}
public void setPublisher(String publisher) {
this.publisher = publisher
}
public String getState() {
return state
}
public void setState(String state) {
this.state = state
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)