- 다른 뜻에 대해서는 PHP file_get_contents() 문서를 참조하십시오.
- file_get_contents
- read
- ReadAllText
1 Bash
Bash
Copy
str=`cat test.txt`
# John Smith
2 Cmd
Bash
Copy
for /f "delims=" %a in ('type test.txt') do @set str=%a
echo %str%
3 C#
C#
Copy
string str = System.IO.File.ReadAllText(@"test.txt");
// John Smith
C#
Copy
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 Java
Java
Copy
String content = new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir"),"test.txt")));
System.out.println(content);
5 JavaScript
JavaScript
Copy
var xhr = new XMLHttpRequest();
xhr.open("GET",'http://example.zetawiki.com/txt/utf8test.txt',false);
xhr.send();
console.log( xhr.responseText );
JavaScript
Copy
function file_get_contents(url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.send();
return xhr.responseText;
}
console.log( file_get_contents('http://example.zetawiki.com/txt/utf8test.txt') );
6 Objective-C
Objective-C
Copy
// ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <NSURLConnectionDelegate> {
NSURLConnection* urlconn;
}
@end
Objective-C
Copy
// ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
urlconn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.zetawiki.com/txt/utf8test.txt"]] delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
}
@end
7 PHP
PHP file_get_contents() 문서를 참고하십시오.
PHP
Copy
$str = file_get_contents('test.txt');
// John Smith
8 Python
Python
Copy
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
Python
Copy
f = open('name.txt')
print( f.read() )
f.close()
Python
Copy
with open('name.txt') as f:
print( f.read() )
9 Ruby
Ruby
Copy
str = open('test.txt').read
# John Smith
Ruby
Copy
require 'open-uri'
h = open('http://example.zetawiki.com/txt/utf8test.txt');
contents = h.read
print contents
10 UnityScript
JavaScript
Copy
var www:WWW = new WWW("http://example.zetawiki.com/txt/utf8test.txt");
yield www;
Debug.Log(www.text);
11 같이 보기
편집자 Jmnote
로그인하시면 댓글을 쓸 수 있습니다.
리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― …리눅스 Python 2.7 컴파일 설치 ― Jmnote리눅스 Python 2.7 컴파일 설치 ― ㅇㅇㅇ미운코딩새끼 ― 승호 도령미운코딩새끼 ― 불탄고등어미운코딩새끼 ― 김레이미운코딩새끼 ― 호박이미운코딩새끼 ― Junhg0211미운코딩새끼 ― 김왼손미운코딩새끼 ― 용딘이미운코딩새끼 ― Pinkcrimson유기농냠냠파이썬 ― 호박유기농냠냠파이썬 ― 이에스유기농냠냠파이썬 ― 이승현파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― John Jeong파이썬 global ― Jmnote파이썬 global ― John Jeong