<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JS: write to txt/ определенная строка]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=7905&amp;type=atom" />
	<updated>2012-12-24T08:55:01Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=7905</id>
		<entry>
			<title type="html"><![CDATA[Re: JS: write to txt/ определенная строка]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=67458#p67458" />
			<content type="html"><![CDATA[<div class="quotebox"><blockquote><p>Мне необходимо сделать запись в txt файл в определённую строку (в конец)</p><p>и проставляет вместо первой табуляции любой знак (&quot;DoneMark&quot;)<br />далее переходит на след строку, и удаляя старый, снова ставит знак<br />для того чтобы отметить выполняемую в данный момент строку</p><p>У меня возникла острая нужда дописать в текущую выполняемую строку через знак \t один символ.</p></blockquote></div><p>Так пробовали?<br /></p><div class="codebox"><pre><code>
Прочитать файл построчно, запоминая каждую строку в массиве
Обработать каждый элемент массива (изменить, удалить, добавить строку или части строк)
Добавить (если необходимо) новый элемент в конец массива
Записать весь массив в тот же файл
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Rumata]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24846</uri>
			</author>
			<updated>2012-12-24T08:55:01Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=67458#p67458</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: write to txt/ определенная строка]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=67453#p67453" />
			<content type="html"><![CDATA[<p><span style="color: Green">Перенёс.</span></p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2012-12-24T08:25:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=67453#p67453</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: write to txt/ определенная строка]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=67449#p67449" />
			<content type="html"><![CDATA[<p>Да, он используется в Ps</p>]]></content>
			<author>
				<name><![CDATA[Maxfashko]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29211</uri>
			</author>
			<updated>2012-12-24T07:56:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=67449#p67449</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: write to txt/ определенная строка]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=67446#p67446" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>Maxfashko пишет:</cite><blockquote><p>Если ошибся разделом и мне в java, прошу прощения</p></blockquote></div><p>Всё-таки это больше пошоже на JS (какой в java тип данных var?), но не браузерный. Зачем в браузерном JS методы работы с файлами, да и незнакомые какие-то. Может это серверный JS или встроенный в какое либо приложение (Photoshop?).</p>]]></content>
			<author>
				<name><![CDATA[wisgest]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=3850</uri>
			</author>
			<updated>2012-12-24T07:29:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=67446#p67446</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[JS: write to txt/ определенная строка]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=67443#p67443" />
			<content type="html"><![CDATA[<p>Здравствуйте!</p><p>Уже на двух форумах я потерпел неудачу, никто не смог толком ничего сказать <img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /></p><p>Мне необходимо сделать запись в txt файл в определённую строку (в конец)</p><br /><p>Вот код, который считывает определённую строку отмеченную знаком<br />А в неё мне нужно сделать запись. <br />Именно в текстовик! Так как запись будет читать другая программа</p><br /><br /><p>код открывает текстовик данного вида<br />1015\t9999\t10x15<br />3000\t8789\t10x15<br />и т.д</p><p>и проставляет вместо первой табуляции любой знак (&quot;DoneMark&quot;)<br />далее переходит на след строку, и удаляя старый, снова ставит знак<br />для того чтобы отметить выполняемую в данный момент строку</p><p>У меня возникла острая нужда дописать в текущую выполняемую строку через знак \t один символ.</p><p>чтобы получилось данное:<br />1015\t9999\t10x15\tV</p><br /><p>Прошу помощи у знатоков.</p><div class="codebox"><pre><code>listFile.open(&quot;e&quot;, &quot;TEXT&quot;, &quot;????&quot;);

// ищем последнее выполненную строчку, отмеченную знаком &quot;&gt;&quot;
do {
    var previousPos = listFile.tell();
    currentLine = listFile.readln();
    var currentPos = listFile.tell();
    var seekDelta = currentPos - previousPos - currentLine.length;
} while(!listFile.eof &amp;&amp; currentLine.search(doneMark) &lt; 0);

// запоминаем, добрались ли мы до конца файла (т.к. в дальнейшем будем пользоваться сдвигом, и .eof может поменять значение)

var endOfFile = false;
if (listFile.eof) endOfFile = true;

if (currentLine.search(doneMark) &gt; 0) {
// если в файле найден знак &quot;&gt;&quot;
// заменяем его на пробел
    var signPos = currentLine.indexOf(doneMark) - currentLine.length - seekDelta;
    listFile.seek(signPos, 1);
    listFile.write(separator);
};

// если мы уперлись в конец файла, сдвигаемся в начало
if (endOfFile) {
    listFile.seek (0,0);
    previousPos = 0 } 
else {
    previousPos = currentPos;
    listFile.seek(- signPos - 1, 1);};
    
// считываем строчку, с которой будем работать
currentLine = listFile.readln();

currentPos = listFile.tell();
seekDelta = currentPos - previousPos - currentLine.length;

// заменяем в рабочей строке пробел на знак &quot;&gt;&quot;
var signPos = currentLine.indexOf(separator) - currentLine.length - seekDelta;
listFile.seek(signPos, 1);
listFile.write(doneMark);</code></pre></div><p>Пробовал сделать так</p><div class="codebox"><pre><code>var XPos =currentLine.length;
listFile.seek(XPos, 1);
listFile.write(&#039;V&#039;);</code></pre></div><br /><p>Но пишет не совсем в конец строки</p><p>Если ошибся разделом и мне в java, прошу прощения</p>]]></content>
			<author>
				<name><![CDATA[Maxfashko]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=29211</uri>
			</author>
			<updated>2012-12-24T05:27:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=67443#p67443</id>
		</entry>
</feed>
