“Baca file teks di JavaScript” Kode Jawaban

Baca file teks di JavaScript

fetch("file.txt")
	.then((response) => {
  		return response.text();
	})
	.then((text) => {
  		console.log(text);
	});
Embarrassed Earthworm

Baca File JavaScript

// As with JSON, use the Fetch API & ES6
fetch('something.txt')
  .then(response => response.text())
  .then(data => {
  	// Do something with your data
  	console.log(data);
  });
Kaotik

JavaScript Baca baris file ke array vanilla

const fileList = event.target.files;
let fileContent = "";

const fr = new FileReader();
fr.onload = () => {
  fileContent = fr.result;
  console.log('Commands', fileContent);
}

fr.readAsText(fileList[0]);
Condemned Civet

JS membaca file teks

<!-- No need for fetch or ajax.
 Use the widely supported FileReader api. -->
<input type="file" name="inputfile" id="inputfile">
<pre id="output"></pre>
<script type="text/javascript">
	document.getElementById('inputfile')
		.addEventListener('change', function() {

			var fr = new FileReader();
			fr.onload = function() {
				document.getElementById('output')
					.textContent = fr.result;
			}

			fr.readAsText(this.files[0]);
		})
</script>
P. Tune

Jawaban yang mirip dengan “Baca file teks di JavaScript”

Pertanyaan yang mirip dengan “Baca file teks di JavaScript”

Lebih banyak jawaban terkait untuk “Baca file teks di JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya