一、读取文件内容
html
<input type="file" accept=".csv,.txt" (change)="openFile($event)">
ts
openFile(event: any): void {
const input = event.target;
const reader = new FileReader();
reader.onload = (() => {
if (reader.result) {
console.log(reader.result);
}
});
reader.readAsText(input.files[0], 'utf-8');
}
文件:
大寺,日本,美国,中国,韩国
12,13,14,11,15
23,24,25,23,26
33,34,36,37,34
Log: