LINUX.ORG.RU
ФорумTalks

JavaScript


0

0

Давно я JavaScript изучал...

Покажите обычный пример записи в файл и чтение.
Может есть русскоязычный ресурс посвященный JavaScript?
С документацией русской.

anonymous

Re: JavaScript

> Покажите обычный пример записи в файл и чтение.

На стороне сервера естественно.

anonymous ()

Re: JavaScript

Обратитесь к Биллу Гейтсу. Он вам про JScript под .NET всё расскажет. А здесь сайт про несколько другое ПО.

ЗЫ. За пиво могу прислать пример под JS CLR.:)

anonymous ()

Re: JavaScript

> С документацией русской.

Учи, студень, албанский:

Reading from a File

Use the read, readln, and readByte methods to read from a file.

The read method reads the specified number of bytes from a file and returns a string.

fileObj.read(count);

Here, fileObj is a File object, and count is an integer specifying the number of bytes to read. If count specifies more bytes than are left in the file, then the method reads to the end of the file.

The readln method reads the next line from the file and returns it as a string.

fileObj.readln();

Here, fileObj is a File object. The line-separator characters (either \r\n on Windows or just \n on Unix or Macintosh) are not included in the string. The character \r is skipped; \n determines the actual end of the line. This compromise gets reasonable behavior on all platforms.

The readByte method reads the next byte from the file and returns the numeric value of the next byte, or -1.

fileObj.readByte();

Writing to a File

The methods for writing to a file are write, writeln, writeByte, and flush.

The write method writes a string to the file. It returns true if successful and false otherwise.

fileObj.write(string);

Here, fileObj is a File object, and string is a JavaScript string.

The writeln method writes a string to the file, followed by \n (\r\n in text mode on Windows). It returns true if the write was successful and false otherwise.

fileObj.writeln(string);

The writeByte method writes a byte to the file. It returns true if successful and false otherwise.

fileObj.writeByte(number);

Here, fileObj is a File object and number is a number.

When you use any of these methods, the file contents are buffered internally. The flush method writes the buffer to the file on disk. This method returns true if successful and false otherwise.

fileObj.flush();

anonymous ()
Ответ на: Re: JavaScript от anonymous

Re: JavaScript

> На стороне сервера естественно.

Не интересно. Мне надо на стороне клиента писать и читать файлы, используя JavaScript. Неужели в такой продвинутой технологии нельзя столь элементарные вещи делать?

anonymous ()
Ответ на: Re: JavaScript от Pi

Re: JavaScript

Вы случайно не путаете JavaScript, который в HTML используют с чем-то другим?

anonymous ()
Ответ на: Re: JavaScript от anonymous

Re: JavaScript

Жирно будет.

anonymous ()
Ответ на: Re: JavaScript от Pi

Re: JavaScript

Дык кто ж запретит то на стороне сервера? Питону в Зопе тоже никто не запрещает, и Java в JSP тоже.

Ясно, что на стороне бровзера или внутри ActionScript никому и в гойлову не придёт разрежать пейсать файлы.

anonymous ()
Ответ на: Re: JavaScript от Pi

Re: JavaScript

Если JaveScript'ом можно писать в читать/писать на сервере, не работает вот это:

<html>
	<head>
		<title>Reading from file</title>
	</head>
	
	<body>
	
		<p>File in this directory:</p>
		
		<script LANGUAGE="JAVASCRIPT">
			document.write("Hello!");
			x = new File("./log.tmp");
			fileIsOpen = x.open("r");
			if (fileIsOpen) {
				document.write("File name: " + x + "<BR>");
				while (!x.eof()) {
					line = x.readln();
					document.write(line+"<br>");
				}
				if (x.error() != 0)
					document.write("error reading file" + "<BR>");
				x.close();
			}
			if (!fileIsOpen)
				document.write("<p>File not opened!</p>");
		</script>
</body>
</html>

anonymous ()
Ответ на: Re: JavaScript от anonymous

Re: JavaScript

С полным путем к файлу тоже не получается.

anonymous ()
Ответ на: Re: JavaScript от anonymous

Re: JavaScript

ЛОЛ, а может надо сначала документ открыть, а потом писать?

т.е. так:
x = new File("./log.tmp");
fileIsOpen = x.open("r");
document.write("Hello!");

shuthdar ★★★ ()
Ответ на: Re: JavaScript от anonymous

Re: JavaScript

Богатые возможности для работы вирусов и троянов?

anonymous ()
Ответ на: Re: JavaScript от shuthdar

Re: JavaScript

Нет не надо.

> fileIsOpen = x.open("r");
Что я вижу? Правильно - r - чтение.
Не читает.

anonymous ()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.