精华内容
下载资源
问答
  • Filehandle
    2021-03-09 19:06:02

    2013-02-22 00:22:11

    1

    Running this code produces an error stating "readline() on closed filehandle SEQFILE at line 14." Previous searches have all commented on how one should put some type of conditional after open. Doing so just kills the program (i left it out so I could see why it didn't open). I would guess the deeper problem is why is it not opening my file?

    #!/usr/bin/perl -w

    #Ask user to point to file location and collect from the keyboard

    print "Please specify the file location: \n";

    $seq = ;

    #Remove the newline from the filename

    chomp $seq;

    #open the file or exit

    open (SEQFILE, $seq);

    #read the dna sequence from the file and store it into the array variable @seq1

    @seq1 = ;

    #Close the file

    close SEQFILE;

    #Put the sequence into a single string as it is easier to search for the motif

    $seq1 = join( '', @seq1);

    #Remove whitespace

    $seq1 =~s/\s//g;

    #Use regex to say "Find 3 nucelotides and match at least 6 times

    my $regex = qr/( ([ACGT]{3}) \2{6,} )/x;

    $seq1 =~ $regex;

    printf "MATCHED %s exactly %d times\n", $2, length($1)/3;

    exit;

    更多相关内容
  • Log::Any::Adapter::FileHandle - 将消息转发到文件句柄的基本 Log::Any::Adapter 概要 use Log::Any qw($log); use Log::Any::Adapter; # Send all logs to Log::Any::Adapter::FileHandle Log::Any::Adapter->...
  • SpringBoot_FileHandle_OpenOffice SpringBoot文件上传下载,整合OpenOffice+pdf.js实现office文件预览 文件上传使用MultipartFile对象、下载使用传统IO流、jobconverter结合OpenOffice把office文件转为pdf文件、...
  • 而在Swift语言里可以通过FileHandle来处理。 下面通过代码示例来讲解下FileHandle的用法。 首先先定义一个文件路径,作为测试文件 let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, ....

    在项目中我们经常有针对二进制或者文本文件进行局部读写、追加数据等需求。在C语言里用fopen系列函数就能解决。而在Swift语言里可以通过FileHandle来处理。

    下面通过代码示例来讲解下FileHandle的用法。

    首先先定义一个文件路径,作为测试文件

    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "test.txt"
    

    接下来判断文件是否存在,不存在就创建。

    注意:由于FileHandle的创建要求文件必须存在,这和C语言的fopen不同,C语言的fopen可以负责在文件不存在时创建,而FileHandle不行。

    if !FileManager.default.fileExists(atPath: path) {
        FileManager.default.createFile(atPath: path, contents: nil, attributes: nil)
    }
    

    接下来,我们创建一个FileHandle

    let fileHandle = FileHandle(forWritingAtPath: path)!
    

    简化起见我这里用“!强制类型为非空,实际开发中请用if分支,不再赘述。

    将文件指针移动到文件末尾。

    fileHandle.seekToEndOfFile()
    

    进入写入数据的阶段,我这里写入字符串hello, world!

    fileHandle.write("hello, world!".data(using: .utf8)!)
    

    最后,记得要关闭文件。

    try? fileHandle.close()
    

    文件关闭后,读一下现在文件里的数据并且打印出来。

    if let content = try? String(contentsOfFile: path, encoding: .utf8) {
        print(content)
    }
    

    如果是首次运行,打印结果是hello, world!,如果再次运行,结果会变成hello, world!hello, world!,依此类推。

    完整代码示例:

    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + "test.txt"
    if !FileManager.default.fileExists(atPath: path) {
        FileManager.default.createFile(atPath: path, contents: nil, attributes: nil)
    }
    
    let fileHandle = FileHandle(forWritingAtPath: path)!
    fileHandle.seekToEndOfFile()
    fileHandle.write("hello, world!".data(using: .utf8)!)
    try? fileHandle.close()
    
    if let content = try? String(contentsOfFile: path, encoding: .utf8) {
        print(content)
    }
    

    其它分享:

    2021年遭遇苹果审核2.3.1的开发过审经历

    4.2、4.3、Other和封号相关的技术性应对方案

    如何有效的向苹果哭诉


    移动开发者的小伙伴们可以加我的公众号风海铜锣的加群菜单栏中申请加群完成加群申请,一起共同进步。

    展开全文
  • FileHandle::Unget-开源

    2021-05-03 06:27:07
    支持多字节unget的Perl FileHandle
  • import com.badlogic.gdx.files.FileHandle; //導入方法依賴的package包/類private void updateFiles(boolean push){if(push) stack.push(directory);navigation.setText(directory.toString());GlyphLayout layout ...

    import com.badlogic.gdx.files.FileHandle; //導入方法依賴的package包/類

    private void updateFiles(boolean push){

    if(push) stack.push(directory);

    navigation.setText(directory.toString());

    GlyphLayout layout = Pools.obtain(GlyphLayout.class);

    layout.setText(Core.font, navigation.getText());

    if(layout.width < navigation.getWidth()){

    navigation.setCursorPosition(0);

    }else{

    navigation.setCursorPosition(navigation.getText().length());

    }

    Pools.free(layout);

    files.clearChildren();

    FileHandle[] names = getFileNames();

    Image upimage = new Image("icon-folder-parent");

    TextButton upbutton = new TextButton(".." + directory.toString());

    upbutton.clicked(()->{

    directory = directory.parent();

    updateFiles(true);

    });

    upbutton.left().add(upimage).padRight(4f).size(14*2);

    upbutton.getCells().reverse();

    files.top().left().add(upbutton).align(Align.topLeft).fillX().expandX().height(50).pad(2).colspan(2);

    upbutton.getLabel().setAlignment(Align.left);

    files.row();

    ButtonGroup group = new ButtonGroup();

    group.setMinCheckCount(0);

    for(FileHandle file : names){

    if( !file.isDirectory() && !filter.test(file)) continue; //skip non-filtered files

    String filename = file.name();

    TextButton button = new TextButton(shorten(filename), "toggle");

    group.add(button);

    button.clicked(()->{

    if( !file.isDirectory()){

    filefield.setText(filename);

    updateFileFieldStatus();

    }else{

    directory = directory.child(filename);

    updateFiles(true);

    }

    });

    filefield.changed(()->{

    button.setChecked(filename.equals(filefield.getText()));

    });

    Image image = new Image(file.isDirectory() ? "icon-folder" : "icon-file-text");

    button.add(image).padRight(4f).size(14*2f);

    button.getCells().reverse();

    files.top().left().add(button).align(Align.topLeft).fillX().expandX()

    .height(50).pad(2).padTop(0).padBottom(0).colspan(2);

    button.getLabel().setAlignment(Align.left);

    files.row();

    }

    pane.setScrollY(0f);

    updateFileFieldStatus();

    if(open) filefield.clearText();

    }

    展开全文
  • FileHandle An object-oriented wrapper for a file descriptor. --文件描述符的面向对象的包装者 --所以文件句柄就是对文件描述符的包装者 Declaration class FileHandle : NSObject Overview --概览 You ...

    Class

    FileHandle

    An object-oriented wrapper for a file descriptor.

     --文件描述符的面向对象的包装者

    --所以文件句柄就是对文件描述符的包装者

    Declaration

    class FileHandle : NSObject

    Overview                                  --概览

    You use file handle objects to access data associated with files, sockets, pipes, and devices. For files, you can read, write, and seek within the file. For sockets, pipes, and devices, you can use a file handle object to monitor the device and process data asynchronously.

             --您可以使用文件句柄对象访问文件、套接字、管道和设备相关联的数据。 对于文件,您可以在文件中读取、写入和查找。 对于套接字、管道和设备,您可以使用文件句柄对象来异步监视设备和处理数据。

     

    Most creation methods for FileHandle cause the file handle object to take ownership of the associated file descriptor. This means that the file handle object both creates the file descriptor and is responsible for closing it later, usually when the file handle object itself is deallocated. If you want to use a file handle object with a file descriptor that you created, use the init(fileDescriptor:) method or use the init(fileDescriptor:closeOnDealloc:) method and pass false for the flag parameter.

            --FileHandle的大多数创建方法都会导致文件句柄对象取得相关文件描述符的所有权。 这意味着文件句柄对象既创建文件描述符,又负责稍后关闭它,通常是在文件句柄对象本身被释放时。 如果要将文件句柄对象与您创建的文件描述符一起使用,请使用init(fileDescriptor:)方法或使用init(fileDescriptor:closeOnDealloc:)方法并为flag参数传递false。

    Run Loop Considerations                    --运行循环时的考虑事项

    When using a file handle object to communicate asynchronously with a socket, you must initiate the corresponding operations from a thread with an active run loop. Although the read, accept, and wait operations themselves are performed asynchronously on background threads, the file handle uses a run loop source to monitor the operations and notify your code appropriately. Therefore, you must call those methods from your application’s main thread or from any thread where you have configured a run loop and are using it to process events.

             --使用文件句柄对象与套接字异步通信时,必须具有活动Run循环的线程启动相应的操作。 尽管读取、接受和等待操作本身在后台线程上异步执行,但文件句柄使用Run循环源来监视操作并适当地通知您的代码。 因此,您必须从 应用程序的主线程 或 已配置Run循环的(并使用它来处理事件的)线程中 调用这些方法。

    For more information about configuring and using run loops, see Threading Programming Guide.

            --有关配置和使用运行循环的更多信息,请参见Threading Programming Guide

     

    Topics

    Getting a File Handle                  --获取文件句柄

    init?(forReadingAtPath: String)

    Returns a file handle initialized for reading the file, device, or named socket at the specified path.

    init(forReadingFrom: URL)

    Returns a file handle initialized for reading the file, device, or named socket at the specified URL.

    init?(forWritingAtPath: String)

    Returns a file handle initialized for writing to the file, device, or named socket at the specified path.

    init(forWritingTo: URL)

    Returns a file handle initialized for writing to the file, device, or named socket at the specified URL.

    init?(forUpdatingAtPath: String)

    Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified path.

    init(forUpdating: URL)

    Returns a file handle initialized for reading and writing to the file, device, or named socket at the specified URL.

    class var standardError: FileHandle

    Returns the file handle associated with the standard error file.

    class var standardInput: FileHandle

    Returns the file handle associated with the standard input file.

    class var standardOutput: FileHandle

    Returns the file handle associated with the standard output file.

    class var nullDevice: FileHandle

    Returns a file handle associated with a null device.

     

    Creating a File Handle                 --创建文件句柄

    init(fileDescriptor: Int32)

    Initializes and returns a file handle object associated with the specified file descriptor.

    init(fileDescriptor: Int32, closeOnDealloc: Bool)

    Initializes and returns a file handle object associated with the specified file descriptor and deallocation policy.

     

    Getting a File Descriptor                 --获取文件描述符

    var fileDescriptor: Int32

    The POSIX file descriptor associated with the receiver.

     

    Reading from a File Handle                  --从文件句柄中读数据

    var availableData: Data

    The data currently available in the receiver.

    func readDataToEndOfFile() -> Data

    Synchronously reads the available data up to the end of file or maximum number of bytes.

    Deprecated

    func readData(ofLength: Int) -> Data

    Synchronously reads data up to the specified number of bytes.

    Deprecated

     

    Writing to a File Handle                 --往文件句柄中写数据

    func write(Data)

    Synchronously writes the specified data to the receiver.

    Deprecated

     

    Reading and Writing Using Blocks                 --使用闭包读写数据

    var readabilityHandler: ((FileHandle) -> Void)?

    The block to use for reading the contents of the file handle asynchronously.

    var writeabilityHandler: ((FileHandle) -> Void)?

    The block to use for writing the contents of the file handle asynchronously.

     

    Communicating Asynchronously                 --异步通信

    func acceptConnectionInBackgroundAndNotify()

    Accepts a socket connection (for stream-type sockets only) in the background and creates a file handle for the “near” (client) end of the communications channel.

    func acceptConnectionInBackgroundAndNotify(forModes: [RunLoop.Mode]?)

    Accepts a socket connection (for stream-type sockets only) in the background and creates a file handle for the “near” (client) end of the communications channel.

    func readInBackgroundAndNotify()

    Reads from the file or communications channel in the background and posts a notification when finished.

    func readInBackgroundAndNotify(forModes: [RunLoop.Mode]?)

    Reads from the file or communications channel in the background and posts a notification when finished.

    func readToEndOfFileInBackgroundAndNotify()

    Reads to the end of file from the file or communications channel in the background and posts a notification when finished.

    func readToEndOfFileInBackgroundAndNotify(forModes: [RunLoop.Mode]?)

    Reads to the end of file from the file or communications channel in the background and posts a notification when finished.

    func waitForDataInBackgroundAndNotify()

    Asynchronously checks to see if data is available.

    func waitForDataInBackgroundAndNotify(forModes: [RunLoop.Mode]?)

    Asynchronously checks to see if data is available.

     

    Seeking Within a File                 --在文件中查找

    var offsetInFile: UInt64

    The position of the file pointer within the file represented by the receiver.

    Deprecatedfunc seekToEndOfFile() -> UInt64

    Puts the file pointer at the end of the file referenced by the receiver and returns the new file offset.

    Deprecatedfunc seek(toFileOffset: UInt64)

    Moves the file pointer to the specified offset within the file represented by the receiver.

    Deprecated

     

    Operating on a File                 --对文件进行操作

    func closeFile()

    Disallows further access to the represented file or communications channel and signals end of file on communications channels that permit writing.

    Deprecatedfunc synchronizeFile()

    Causes all in-memory data and attributes of the file represented by the receiver to be written to permanent storage.

    Deprecatedfunc truncateFile(atOffset: UInt64)

    Truncates or extends the file represented by the receiver to a specified offset within the file and puts the file pointer at that position.

    Deprecated

     

    Constants                 --常量

     

    Keys for Notification UserInfo Dictionary

    Strings that are used as keys in a userinfo dictionary in a file handle notification.

     

    Exception Names

    Constant that defines the name of a file operation exception.

     

    Notifications                 --通知

    NSFileHandle posts several notifications related to asynchronous background I/O operations. They are set to post when the run loop of the thread that started the asynchronous operation is idle.

    static let NSFileHandleConnectionAccepted: NSNotification.Name

    This notification is posted when an NSFileHandle object establishes a socket connection between two processes, creates an NSFileHandle object for one end of the connection, and makes this object available to observers by putting it in the userInfo dictionary.

    static let NSFileHandleDataAvailable: NSNotification.Name

    This notification is posted when the file handle determines that data is currently available for reading in a file or at a communications channel.

    class let readCompletionNotification: NSNotification.Name

    This notification is posted when the file handle reads the data currently available in a file or at a communications channel.

    static let NSFileHandleReadToEndOfFileCompletion: NSNotification.Name

    This notification is posted when the file handle reads all data in the file or, if a communications channel, until the other process signals the end of data.

    Initializers

    init?(coder: NSCoder)

     

    Instance Methods                 --实例方法

    func close()

    func offset() -> UInt64

    func read(upToCount: Int) -> Data?

    func readToEnd() -> Data?

    func seek(toOffset: UInt64)

    func seekToEnd() -> UInt64

    func synchronize()

    func truncate(atOffset: UInt64)

    func write<T>(contentsOf: T)

     

    Relationships                 --继承关系

    Inherits From

    Conforms To

    See Also

    Managed File Access

    class NSFileSecurity

    A stub class that encapsulates security information about a file.

    class NSFileVersion

    A snapshot of a file at a specific point in time.

    class FileWrapper

    A representation of a node (a file, directory, or symbolic link) in the file system.

    展开全文
  • perl 文件句柄 *Perl readline() on closed filehandle FILE 或Can’t open file 问题解决方案 ) perl 读取一个文件,然后把读出来的数据写进另一个文件中去! 本人初学perl, 做基于人工智能的蛋白质结构预测课题,...
  • 可以使用FileHandle包,可以避免变量覆盖的现象。 use FileHandle; $fileHandleName= new FileHandle("filename"); $line=<$fileHandleName>;   close() 关闭文件句柄 实际上,perl会在句柄超出范围或...
  • 文件操作-FileHandle

    千次阅读 2015-06-05 07:08:00
    1.使用文件句柄(FileHandle)的对象可以对文件的内容进行操作 2.文件的写操作 2.1.将新加的字符在文件的前面添加,而不清空文件内容,只是替换从文件开头的文字 NSFileHandle *fhw = [NSFileHandle ...
  • 作者译读的LibGdx的版本是1.9.1 FileHandle类,表示在文件系统上的文件,一个文件或目录的路径,android sd卡,或Android资产目录。
  • use FileHandle;my %fh; my @filehandlename=("A","B","C"); ##文件句柄的名字; for my $filehandlename (@filehandlename){  $fh{$filehandlename}=FileHandle->new("> $filename"); ##$filename 代表...
  • iOS study Day12-FileHandle读取和写入

    千次阅读 2014-04-02 16:00:57
    //打开一个文件,一次从中读取128个字节,并将其写到终端。 //从终端接受输入任意...可以利用FileHandle的方法 //fileHandleWithStandardOutput //fileHandleWithStandardInput //来获得终端输出的句柄。 #import
  • OldReadFile(FileHandle,Event,ApcRoutine,ApcContext,IoStatusBlock,Buffer,Length,ByteOffset,Key); } 用FileHandle获得文件名不应该使用ObReferenceObjectByHandle吗?蓝啊蓝啊蓝啊蓝 <!-- ...
  • 1.小文件的下载方法  A.NSURL *url = [NSURL URLWithString:@"http://image2.sina.com.cn/ent/v/m/p/2005-11-11/U92P28T3D893697F329DT20051111200426.jpg"];  NSData *data = [NSData dataWithCont
  • <p>I'm currently investigating some PHP-code and I'm trying to make it more up to date. I found a function, which retrieves a filehandle (via <code>fopen). <p>The returntype is <code>stream</code>. I...
  • Reopening a Standard Filehandle We mentioned earlier that if you were to reopen a filehandle (that is, if you were to open a filehandle FRED when you've got an open filehandle named FRED), the ...
  • 5.7. Opening a Filehandle You've seen that Perl provides three filehandlesSTDIN, STDOUT, and STDERRwhich are automatically open to files or devices established by the program's parent process ...
  • 然而,我们可以让Python从头开始读来解决这个问题:fileHandle = open ( 'test.txt' ) garbage = fileHandle.readline() fileHandle.seek ( 0 ) print fileHandle.readline() # "This is a test." fileHandle.close...
  • LibGDX_2.4: 文件的操作(FileHandle

    千次阅读 2015-12-06 02:12:15
    2. FileHandle FileHandle 类,代表一个文件或文件夹,文件或文件夹可以来自 文件系统,classpath, Android SD 卡,assets 资源文件目录。 文件可以存储在多个地方,分别对应不同的存储类型,下面介绍常用的...
  • 现在打开一个文件以进行写操作:1.fileHandle = open ( 'test.txt', 'w' )fileHandle = open ( 'test.txt','w' )‘w'是指文件将被写入数据,语句的其它部分很好理解。下一步就是将数据写入文件:1.fileHandle.write ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 9,266
精华内容 3,706
关键字:

Filehandle