"함수 readAllText()"의 두 판 사이의 차이

잔글 (로봇: 자동으로 텍스트 교체 (-http://zetawiki.com/utf8test.txt +http://zetawiki.com/ex/txt/utf8test.txt))
68번째 줄: 68번째 줄:
- (void)viewDidLoad {
- (void)viewDidLoad {
     [super viewDidLoad];
     [super viewDidLoad];
     urlconn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://zetawiki.com/utf8test.txt"]] delegate:self];
     urlconn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://zetawiki.com/ex/txt/utf8test.txt"]] delegate:self];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
113번째 줄: 113번째 줄:
<source lang='Ruby'>
<source lang='Ruby'>
require 'open-uri'
require 'open-uri'
h = open('http://zetawiki.com/utf8test.txt');
h = open('http://zetawiki.com/ex/txt/utf8test.txt');
contents = h.read
contents = h.read
print contents
print contents
121번째 줄: 121번째 줄:
[[category: UnityScript]]
[[category: UnityScript]]
<source lang='javascript'>
<source lang='javascript'>
var www:WWW = new WWW("http://zetawiki.com/utf8test.txt");
var www:WWW = new WWW("http://zetawiki.com/ex/txt/utf8test.txt");
yield www;
yield www;
Debug.Log(www.text);
Debug.Log(www.text);

2015년 7월 29일 (수) 12:32 판

  다른 뜻에 대해서는 PHP file_get_contents() 문서를 참조하십시오.
file_get_contents
read
ReadAllText

1 Bash

str=`cat test.txt`
# John Smith

2 Cmd

for /f "delims=" %a in ('type test.txt') do @set str=%a
echo %str%

3 C#

string str = System.IO.File.ReadAllText(@"test.txt");
// John Smith
public static string file_get_contents(string filepath)
{
   try
   {
       if (filepath.ToLower().IndexOf("tp://") > 0)
       {
           System.Net.WebClient wc = new System.Net.WebClient();
           byte[] response = wc.DownloadData(filepath);
           return System.Text.Encoding.UTF8.GetString(response);
       }
       System.IO.StreamReader sr = new System.IO.StreamReader(filepath);
       string contents = sr.ReadToEnd();
       sr.Close();
       return contents;
   }
   catch
   {
       return "";
   }
}

4 Objective-C

//  ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <NSURLConnectionDelegate> {
    NSURLConnection* urlconn;
}
@end
//  ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    urlconn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://zetawiki.com/ex/txt/utf8test.txt"]] delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
@end

5 PHP

$str = file_get_contents('test.txt');
// John Smith

6 Python

with open('name.txt', 'w') as w: w.write('His name is\nJohn Smith')

f = open('name.txt', 'r')
print( f.read() )
f.close()
# His name is
# John Smith
f = open('name.txt')
print( f.read() )
f.close()
with open('name.txt') as f:
    print( f.read() )

7 Ruby

str = open('test.txt').read
# John Smith
require 'open-uri'
h = open('http://zetawiki.com/ex/txt/utf8test.txt');
contents = h.read
print contents

8 UnityScript

var www:WWW = new WWW("http://zetawiki.com/ex/txt/utf8test.txt");
yield www;
Debug.Log(www.text);

9 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}