Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在AS3中使用.txt文件而不是.dat文件在flash pro cs6中测试android应用程序的air_Android_Actionscript 3_Adobe_Flash Cs6 - Fatal编程技术网

如何在AS3中使用.txt文件而不是.dat文件在flash pro cs6中测试android应用程序的air

如何在AS3中使用.txt文件而不是.dat文件在flash pro cs6中测试android应用程序的air,android,actionscript-3,adobe,flash-cs6,Android,Actionscript 3,Adobe,Flash Cs6,您好,我想我的应用程序,我在flash pro cs6使用安卓的空气读取速度从.txt文件,而不是一个.dat文件 我该如何更改下面在Actionscript 3中完成的代码,以便更轻松地更改数字和测试速度计应用程序在不同的速度信息下再次工作 你也可以让我知道我将如何把数字在.txt文件中读取 目前,我只是使用手机上的gps二进制记录速度文件来测试这个,但我无法更改这个.dat文件的值,所以我无法测试一些最高速度 以下是我的代码,我将如何更正以使用txt文件: package { import

您好,我想我的应用程序,我在flash pro cs6使用安卓的空气读取速度从.txt文件,而不是一个.dat文件

我该如何更改下面在Actionscript 3中完成的代码,以便更轻松地更改数字和测试速度计应用程序在不同的速度信息下再次工作

你也可以让我知道我将如何把数字在.txt文件中读取

目前,我只是使用手机上的gps二进制记录速度文件来测试这个,但我无法更改这个.dat文件的值,所以我无法测试一些最高速度

以下是我的代码,我将如何更正以使用txt文件:

package
{
import flash.events.EventDispatcher;
import flash.events.GeolocationEvent;
import flash.events.TimerEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.utils.Timer;

public class GeolocationSimulate
    extends EventDispatcher
    implements IGeolocation
{   
    static private const DEFAULT_DELAY :Number = 1000;
    static private const FILE          :String = "gps.dat";

    private var filestream :FileStream;
    private var timer      :Timer;

    public function GeolocationSimulate()
    {
        timer = new Timer( DEFAULT_DELAY );
        timer.addEventListener( TimerEvent.TIMER, handleTimer );
        timer.start();

        var file :File = File.userDirectory;
        file = file.resolvePath( FILE );            
        filestream = new FileStream();
        filestream.open( file, FileMode.READ );
    }

    public function setRequestedUpdateInterval( interval :Number ) :void
    {
        timer.delay = interval;
    }

    private function handleTimer( e :TimerEvent ) :void
    {
        if( filestream != null )
        {
            var speed :Number;

            if( filestream.bytesAvailable )
            {
                speed = filestream.readFloat();
            }
            else
            {
                filestream.position = 0;
                speed = filestream.readFloat();
            }

            dispatchEvent(
                new GeolocationEvent(
                    GeolocationEvent.UPDATE,
                    false,
                    false,
                    0,
                    0,
                    0,
                    0,
                    0,
                    speed,
                    0,
                    0
                )
            );
        }
    }
}

}

不确定这是否是您想要的,但您可以通过以下方式将文本写入文件:

    var file :File = File.userDirectory;
    file = file.resolvePath( FILE );            
    filestream = new FileStream();
    filestream.open( file, FileMode.WRITE); (or FileMode.APPEND if you want to add text to end of existing file)
    filestream.writeUTFBytes(yourTextHere);
    filestream.close();

谢谢你的回答,但我可能让你误解了这个问题,我想要的是我上面的代码读取一个.txt文件,而不是一个二进制的.dat文件,我不能编辑,因为它只是gps号码,存储在我的手机上,而我在开车,我复制了它,并用它来模拟我的速度计应用程序,同时在我的计算机上测试。有没有可能修改我的代码以使用一个.txt文件而不是我一直使用的其他.dat文件来执行此操作。任何人请帮助我真的被困在这个问题上