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

(새 문서: category: File {{lowercase title}} ;file_get_contents ;ReadAllText ==Bash== category: Bash <source lang='bash'> str=`cat test.txt` # John Smith </source> ==Cmd== category:...)
 
13번째 줄: 13번째 줄:
==Cmd==
==Cmd==
[[category: Cmd]]
[[category: Cmd]]
<source lang='dos'>
<source lang='bash'>
for /f "delims=" %a in ('type test.txt') do @set str=%a
for /f "delims=" %a in ('type test.txt') do @set str=%a
echo %str%
echo %str%

2014년 5월 30일 (금) 15:48 판

file_get_contents
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://jmnote.com/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 UnityScript

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

7 같이 보기

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